Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

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)
SELECT
    f.column1, f.column2, f.column3
FROM
    (SELECT * FROM table1
     UNION ALL
     SELECT * FROM table2
     UNION ALL
     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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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