Re: Question about serial vs. int datatypes

Поиск
Список
Период
Сортировка
От Rory Campbell-Lange
Тема Re: Question about serial vs. int datatypes
Дата
Msg-id 20030608130343.A2914@host0406.cammail.net
обсуждение исходный текст
Ответ на Question about serial vs. int datatypes  (Lynna Landstreet <lynna@gallery44.org>)
Список 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 по дате отправления:

Предыдущее
От: Andrew Gould
Дата:
Сообщение: psqlODBC and Crossover Office 2.0.1
Следующее
От: Ian Barwick
Дата:
Сообщение: Re: update phenomenom