gpt4 book ai didi

database - 最近的(几何)点作为外键

转载 作者:行者123 更新时间:2023-11-29 14:22:51 31 4
gpt4 key购买 nike

我们有两个 (PostgreSQL 9.2) 表。第一城市:

 loc_id    | integer               | not null
name | character varying(40) |
gps_coord | point |

后跟 weather_stations:

 s_id        | integer                | not null
location | character varying(255) | not null
height | integer |
city_loc_id | integer |
gps_coord | point |

利用它们的点坐标,我们如何找到距离气象站最近的城市?我想用这个城市来填充weather_stations的外键(它们是目前全部为 NULL),即 city_loc_id。 (有这样一个外键是个好主意吗?)

我意识到我必须以某种方式使用最近点运算符 (##),但在编写查询时我有点不知所措。

最佳答案

有一个距离运算符可能是您正在寻找的:select point1 <-> point2 . (也有 earthdistance,但对于您的目的来说似乎有些过分了。)

关于database - 最近的(几何)点作为外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16825493/

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