I have an old MSAccess DB and I want to convert it to PostgreSQL. I found DBeaver very useful. Some operations may be done by hand. This is the case of Primary Keys. You must manually set the primary keys. I didn't found another way to do it. So in PGAdmin, I'm setting all this stuff. The client is using constantly this db so I can get data only on holiday when the client is not working and import data on PostgreSQL. My goal is to set the database ready to receive data from the production database. So far, in PGAdmin, I'm setting the Primary Key identity on "Always" and starting from the last number of primary key, setting it by hand. I think this is not the right way to do it. And when I'll start to import the production data, I don't want to set by hand all that stuff. How can I set the primary key ready to start the autoincrement from max of ID?
Asked
Active
Viewed 198 times
1
-
maybe take a look into https://www.postgresql.org/docs/8.1/datatype.html#DATATYPE-SERIAL – Julius Tuskenis Apr 06 '21 at 10:21
-
1@JuliusTuskenis: Version 8.1 is very old and unsupported, please link to the current version: https://www.postgresql.org/docs/current/datatype.html – Frank Heikens Apr 06 '21 at 10:27
-
@FrankHeikens thank you for spotting that. Current version ling is https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-SERIAL (serial types) – Julius Tuskenis Apr 06 '21 at 10:34
-
This is the way I tried but it seems I have to do it again when I will import the final data. Is correct? – Stefano Ferrari Apr 06 '21 at 12:22
1 Answers
0
Using an identity column is the good way. Just set the sequences to a value safely above the current maximum. It doesn't matter if you lose a million sequence values.

Laurenz Albe
- 209,280
- 17
- 206
- 263
-
Thanks. This seems good. My client doesn't push so much data in tables so I can set the sequence to a value above. So I can prepare the whole database and when I will put it in production I will import data and try some tests. Thanks. – Stefano Ferrari Apr 06 '21 at 12:27