Converting Database

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
[email protected]
Posts: 5
Joined: Tue 12 Jan 2010 01:03

Converting Database

Post by [email protected] » Tue 19 Jan 2010 05:37

Sorry if this is to generic but am new to PostgreSQL. I have an existing product that uses another database. I am looking into converting to PostgreSQL. Therefore, I will need to write a conversion program.

The existing db uses the typical integer autoinc fields for the primary key for each table. I would like to do the same in PostgreSQL. Is there a way create my PostgreSQL tables with an integer ID field, import the data and then create my sequences on the ID field where the nextval is some arbitrary integer.

Thanks

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 19 Jan 2010 10:03

You can use SERIAL data type. PostgreSQL automatically creates a sequence for such fields. Use the following statement to set the last value for a sequence:

Code: Select all

SELECT pg_catalog.setval('seq_name', LastVal, false)

[email protected]
Posts: 5
Joined: Tue 12 Jan 2010 01:03

Post by [email protected] » Tue 19 Jan 2010 14:43

Thank you very much. Just to make sure that I understand:
I create the column as a serial.

When importing the rows from the other db I just manually specify the values with the id numbers from the old db.

Then when I have all the data imported, I calculate the next id number and set lastval of the sequence with the commend you mentioned.

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 19 Jan 2010 15:03

Yes, you are right.

Post Reply