Tom*_*mer 2 postgresql geospatial earthdistance
我正在使用Postgresql 9.3和iv'e安装了cube和earthdistance扩展.
我正在尝试按照本教程,所以我有一个简单的事件表,包含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);
Run Code Online (Sandbox Code Playgroud)
但我一直收到这个错误:
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.
Run Code Online (Sandbox Code Playgroud)
所以我用铸造运行同样的东西:
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);
Run Code Online (Sandbox Code Playgroud)
我得到:
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.
Run Code Online (Sandbox Code Playgroud)
好的,最后几个小时后我就明白了:)
显然我正在使用的教程已经过时,正确的语法是这样的:
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1462 次 |
| 最近记录: |