[Tile-serving] [openstreetmap/osm2pgsql] Add unique constraint for geometry tables (#873)

Peter notifications at github.com
Wed Oct 10 00:36:32 UTC 2018


`osm_id` is not unique in the `planet_osm_polygon` table. If there are [no particular option](https://help.openstreetmap.org/questions/66170/how-to-identify-parts-of-the-same-osm_id-in-planet_osm_polygon/66171), that would do something as a `gid`... This issue is a suggestion to add a column `osm_id2` to be used as  `UNIQUE(osm_id,osm_id2)`.  

## Example
    
```sql
ALTER TABLE planet_osm_polygon ADD COLUMN osm_id2 int;
UPDATE planet_osm_polygon
SET  osm_id2 = sub_id
FROM (
  SELECT osm_id, way, row_number() OVER (PARTITION BY osm_id) as sub_id 
  FROM planet_osm_polygon
) t WHERE t.osm_id=planet_osm_polygon.osm_id AND t.way=planet_osm_polygon.way
; -- need time ...  
ALTER TABLE planet_osm_polygon ALTER COLUMN osm_id2 SET NOT NULL;
ALTER TABLE planet_osm_polygon ADD CONSTRAINT osm_uniqids UNIQUE(osm_id,osm_id2);
```


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/osm2pgsql/issues/873
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/tile-serving/attachments/20181009/940028bb/attachment.html>


More information about the Tile-serving mailing list