I just imported some shapefiles with the PostGIS importer. Because several errors and issues I had to split my shapefile in multiple parts. Then I imported them one by one. I thought I can easily merge them later on.

But now there is a problem. The import tool created a primary key called GID. And these identical PKs prohibit the merge. Doeas anybody know how to delete these GIDS, merge all the tables and create new PKs?

I'm thankful for any answer.


I think you can't simply eliminate GID and create a new one, as it will break the PK indexes.

To make sure you end up with a well build table I would do the following:

Create a new table based in any of the original tables. (If you are using pgadmin, you can use the create statement of the original table and give it a new name). After the table created and assuming that that all you tables have the same columns structure, I think you can use INSERT INTO and UNION ALL to try the following:

INSERT INTO new_table (column1, column2, column3)
    f.column1, f.column2, f.column3
    (SELECT * FROM table1
     SELECT * FROM table2
     SELECT * FROM table3) as f;

Notice that columns 1, 2 and 3 represent all the tables columns except the GID, which will be populated automatically.

Hope it helps

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.