【问题标题】:PostgreSQL: How to get all points in certain radiusPostgreSQL:如何获得一定半径内的所有点
【发布时间】:2014-11-26 16:22:53
【问题描述】:

我使用的是 Postgresql 9.3,并且已经安装了 cube 和 earthdistance 扩展。

我正在尝试关注this tutorial,所以我有一个包含 4 个字段的简单事件表:id、name、lat、lng。

现在我正在尝试运行此查询,以获取 1 公里半径内的所有事件:

SELECT events.id, events.name FROM events WHERE earth_box(31.789225, 34.789612, 1000) @> ll_to_earth(events.lat, events.lng);

但我不断收到此错误:

20:59:34 Kernel error: ERROR:  function earth_box(numeric, numeric, integer) does not exist
  HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

所以我用铸造做了同样的事情:

  SELECT events.id, events.name FROM events WHERE earth_box(CAST(31.789225 AS float8), CAST(34.789612 AS float8), 1000) @> ll_to_earth(events.lat, events.lng);

我明白了:

   21:16:17 Kernel error: ERROR:  function earth_box(double precision, double precision, integer) does not exist
                                                              ^
      HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

【问题讨论】:

    标签: postgresql geospatial earthdistance


    【解决方案1】:

    好的,几个小时后我终于明白了:)

    显然我使用的教程已经过时了,正确的语法是这样的:

    SELECT events.id, events.name FROM events WHERE earth_box(ll_to_earth(31.789225,34.789612), 1000) @> ll_to_earth(events.lat, events.lng); 
    

    【讨论】:

    • 哎呀,那是我的错。今晚或明天将尝试更新它。
    • @JohannduToit,您尚未更新倒数第二个查询 (SELECT events.id, ...)。不过感谢您的教程:)
    • ll_to_earth 不被视为函数。厄运。 :(
    • 请向我们提供建表脚本。我想看看数据类型
    • @anduplats 你知道这是一个 5 年前的帖子吗?!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    • 2011-05-10
    • 1970-01-01
    相关资源
    最近更新 更多