假设在这个位置发生了一个特殊事件:
{
label: 'Mountain View',
lat: 37.4224764,
lng: -122.0842499
}你将如何存储这些信息,为什么?
1)单表
events: id place_label coordinates(point)2)两个独立的表
events: id place_id
places: place_id label coordinates(point)3)使用jsonb数据类型的单表
events: id place(jsonb)或者另一种方式?
最终目标是使用地理空间扩展(例如EarthDistance、PostGIS)来执行“查找___英里内的所有事件”之类的查询。
发布于 2017-08-24 23:05:44
执行两个单独的表,否则会遇到查询大于需要的点多边形表的缺点。
CREATE TABLE places
(
id_place serial PRIMARY KEY,
name text,
geom geography(POINT)
);
CREATE INDEX ON places USING gist(geom);
CREATE TABLE events
(
id_event serial PRIMARY KEY,
id_place int REFERENCES place,
start_ts timestamp
);最终目标是使用地理空间扩展(例如EarthDistance、PostGIS)来执行“查找___英里内的所有事件”之类的查询。
SELECT *
FROM events AS e
JOIN places AS p USING (id_place)
WHERE ST_DWithin(p.geom, ST_MakePoint(long,lat)::geography, miles*1609);这是miles of (long,lat)中的所有事件。我不会使用earthdistance,我只会使用PostGIS。
https://stackoverflow.com/questions/45871943
复制相似问题