【问题标题】:request error on postgreSQL using postgis (more than one row returned)使用 postgis 在 postgreSQL 上请求错误(返回多行)
【发布时间】:2016-01-27 09:43:25
【问题描述】:

我在使用 postGIS 的 postgreSQL 上有一个包含我国所有 37 000 个城市的列,我正在尝试将他们的 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 的子查询返回了不止一行

我在 stackoverflow 上发现我需要在请求的末尾加上“限制 1”,例如:

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

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

有人知道吗?

【问题讨论】:

    标签: postgresql postgis


    【解决方案1】:

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

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

    【讨论】:

    • 工作!非常感谢!!
    猜你喜欢
    • 1970-01-01
    • 2023-04-01
    • 2019-11-12
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多