What is a suitable Global/Universal Unique Identifier for a PostGIS database?
Two Solutions:
1)Create a single sequence and make all the tables use that sequence, can be done from the beginning or you may create a ID column and update your tables now.
To Create the sequence:
CREATE SEQUENCE universal_sequence;
Then a table:
CREATE TABLE (
colname integer NOT NULL DEFAULT nextval('universal_sequence'));
To Update an existing table id field with new IDs (do it for all the tables that you want to follow the same sequence):
UPDATE table1
SET id=nextval('universal_sequence'));
2)The other solution: Create a temporary sequence and them run the query creating a new ID column.
More here: http://www.postgresql.org/docs/8.4/static/sql-createsequence.html
I would create separate intermediary tables buildings_attach
, parcels_attach
, etc. Then you don't need a global identifier.
The best option is the UUID or GUID. They are built for this reason, globally unique no matter what table. Ugly? Yes but they are the best for this situation.
See https://stackoverflow.com/questions/294933/generate-unique-id-to-share-with-multiple-tables-sql-2008
I have seen methods where people use data from the table to make IDs eg col1 + somestring + col2, I would really really adivse against this (see here). Intelligent IDs are a really bad idea.