感谢MarcB的评论,我意识到问题在于在string_agg函数中进行排序,因此解决方案是:
SELECt routeid, 'SRID=4326;LINESTRING(' || string_agg(lon || ' ' || lat, ',' ORDER BY time ASC) || ')' AS the_geomFROM route_table WHERe observation_time BETWEEN '2012-09-12 10:00:00' AND '2012-09-12 10:15:00'GROUP BY routeid HAVINg COUNT(lon) > 1;


