gpt4 book ai didi

postgresql - UndefinedFunction : ERROR: function st_distance(geography, 几何、数字)不存在

转载 作者:行者123 更新时间:2023-11-29 14:21:00 26 4
gpt4 key购买 nike

我想按距离排序,但出现错误

UndefinedFunction: ERROR:  function st_distance(geography, geometry, numeric) does not exist

.order("ST_Distance(lonlat, ST_Geomfromtext('#{point}'), #{radius}) ")

如果我删除上面的行,它工作正常。

这是怎么回事?

型号

  scope :nearby, lambda { |radius_in_km, lon, lat|
point = GEOG_FACTORY.point(lon, lat)
radius = radius_in_km.to_f*1000
where("ST_DWithin(lonlat, ST_GeomFromText('#{point}'), #{radius} ) ")
.order("ST_Distance(lonlat, ST_Geomfromtext('#{point}'), #{radius}) ")
}

更详细的错误日志

PG::UndefinedFunction: ERROR:  function st_distance(geography, geometry, numeric) does not exist
LINE 1: ...4028 6.530438999999999)'), 100000.0 ) ) ORDER BY ST_Distanc...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
: SELECT "weather_logs".* FROM "weather_logs" WHERE (ST_DWithin(lonlat, ST_GeomFromText('POINT (101.3034028 6.530438999999999)'), 100000.0 ) ) ORDER BY ST_Distance(lonlat, ST_Geomfromtext('POINT (101.3034028 6.530438999999999)'), 100000.0) , "weather_logs"."datetime" ASC LIMIT 20000
Completed 200 OK in 161ms (Views: 0.2ms | ActiveRecord: 5.4ms)

最佳答案

您正在混合地理和几何类型,这就是错误消息的含义。如果您查看 ST_DWithin docs,你会看到签名是ST_DWithin (geometry, geometry, distance) 或者ST_DWithin (geography, geography, distance)。

我不太了解 Ruby,所以我不确定是否有一个 GEOM_Factory 与您使用的 GEO_Factory 等效,但是如果您使用 ST_GeogFromText而不是在您的 where 和 order by 子句中使用 ST_GeomFromText,那么您将处理两个地理区域,这应该可以解决您的问题。

由于您的坐标是纬度/经度 4326,因此使用地理数据类型是合适的。如果您想了解更多关于几何与地理学的实用性,请参阅 this gis.stackexchange question .

关于postgresql - UndefinedFunction : ERROR: function st_distance(geography, 几何、数字)不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26935060/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com