Golang 与 postgres - 无法将变量传递到 ST_DWithin 查询中
对于 Golang 来说非常陌生,无法解决这个问题。任何帮助将不胜感激。
这是我需要帮助的代码。尝试将纬度等传递到下面的查询中,但无法做到。在节点 js 中寻找 ${latitude} 的等效项...
latitude := r.URL.Query().Get("lat")
longitude := r.URL.Query().Get("lon")
radius := r.URL.Query().Get("rad")
row := db.QueryRow(`SELECT "name", "website", "coordinates",
"description", "rating"
FROM geospots
WHERE ST_DWithin("coordinates", ST_MakePoint(latitude = $1,
longitude = $2)::geography, radius = $3)`, latitude, longitude)
Error:
andlers/SpotsInArea.go:15:5: latitude declared but not used
handlers/SpotsInArea.go:16:5: longitude declared but not used
handlers/SpotsInArea.go:17:5: radius declared but not used
Very new to Golang and unable to resolve this. Any help would be highly appreciated.
This is the code I need help with. Trying to pass the latitude etc into the query below, but unable to do it. Looking for the equivalent on ${latitude} in node js...
latitude := r.URL.Query().Get("lat")
longitude := r.URL.Query().Get("lon")
radius := r.URL.Query().Get("rad")
row := db.QueryRow(`SELECT "name", "website", "coordinates",
"description", "rating"
FROM geospots
WHERE ST_DWithin("coordinates", ST_MakePoint(latitude = $1,
longitude = $2)::geography, radius = $3)`, latitude, longitude)
Error:
andlers/SpotsInArea.go:15:5: latitude declared but not used
handlers/SpotsInArea.go:16:5: longitude declared but not used
handlers/SpotsInArea.go:17:5: radius declared but not used
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢@mkopirva
正如所指出的,您不需要
latitude = $1
它应该只是$1
,您已经在查询中定义了$3
但缺少第三个值并确保变量在您访问它们的范围内
Thanks to @mkopirva
As pointed you don't need
latitude = $1
it should be just$1
, You have defined$3
in query but missing the 3rd valueAnd make sure the variable are within the scope where you are accessing them