使用 postgis 在 postgreSQL 上请求错误(返回多行)

request error on postgreSQL using postgis (more than one row returned)

我在使用 postGIS 的 postgreSQL 上有一个包含我国所有 37000 个城市的列,我正在尝试将它们的 POINT(几何列)与 postgis 函数 ST_point(long,lat)放在一起。他们都有不同的经度和纬度数据。

这是我的要求:

update city
set geom_city = (select ST_SetSRID(ST_Point(city.city_long, city.city_lat),4326) from city);

问题是我有这条错误消息说:用作表达式 postgreSQL

的子查询返回的行不止一行

我在 Whosebug 上发现我需要在请求的末尾添加 "Limit 1",例如:

update city
set geom_city = (select ST_SetSRID(ST_Point(city.city_long, city.city_lat),4326) from city LIMIT 1);

这使我的请求有效,但确实在 geom_city 列中写入了所有城市的相同结果。

有人知道吗?

不需要嵌套的SELECT子查询,试试这个:

update city
set geom_city = ST_SetSRID(ST_Point(city_long, city_lat),4326) ;