Re: Question about serial vs. int datatypes - Mailing list pgsql-general

From Rory Campbell-Lange
Subject Re: Question about serial vs. int datatypes
Date
Msg-id 20030608130343.A2914@host0406.cammail.net
Whole thread Raw
In response to Question about serial vs. int datatypes  (Lynna Landstreet <lynna@gallery44.org>)
List pgsql-general
On Thu, Jun 05, 2003 at 04:05:53PM -0400, Lynna Landstreet wrote:
> But... when converting an existing database that already has several hundred
> records in it, I can't make that field serial in PostgreSQL, can I? Because
> I don't want the existing records renumbered - that would break the links
> between the different tables. But if I make the id number just a smallint
> field, then I'm stuck incrementing it manually after the conversion. Is
> there any way around this? Any way to import the existing records with their
> id number intact, and then have it switch to serial after that for new
> records?

Make a new table with a serial type field and then do a \d on that table. You will see that the default value for the
fieldis the next value from the relevant (autocreated) sequence. If you specify a value for the "SERIAL" type field,
thefield will be filled with that rather than a value from the sequence.  

Note that if you do this you need to reset the value of the current sequence. Use something like setval(sequencename)
tomax(your_serial_field). 

Rory

pgsql-general by date:

Previous
From: Andrew Gould
Date:
Subject: psqlODBC and Crossover Office 2.0.1
Next
From: Ian Barwick
Date:
Subject: Re: update phenomenom