Re: Add quto increment to existing column

Поиск
Список
Период
Сортировка
От Greg Williamson
Тема Re: Add quto increment to existing column
Дата
Msg-id 1317948611.27175.YahooMailNeo@web46113.mail.sp1.yahoo.com
обсуждение исходный текст
Ответ на Add quto increment to existing column  (Robert Buckley <robertdbuckley@yahoo.com>)
Список pgsql-general
Robert --

>Hi,
>
>
>I have a column in a table called hist_id with the datatype "integer". When I created the table I assigned this column
theprimary key constraint but didn´t make it an auto-increment column. 
>
>
>How could I do this to an the already existing column?
>
>
>I have created the sequence with the following command but don´t know how to change the existing column to
auto-increment.
>
>
>
>
>$ create sequence hist_id_seq;
>


Perhaps:

ALTER TABLE history_foo ALTER COLUMN hist_id SET DEFAULT nextval('hist_id_seq');

?? (untested)

You may need to to update the sequence to reflect your current highest value for hist_id (or whatever the column is --
setthe sequence using select setval('hist_id_seq', maxid)  so that the next value you get from the sequence doesn't
collidewith existing values. 

HTH,

Greg Williamson


В списке pgsql-general по дате отправления:

Предыдущее
От: Gavin Flower
Дата:
Сообщение: Re: Selecting All Columns Associated With Maximum Value of One Column
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: Backup Database Question