Re: Add quto increment to existing column

Поиск
Список
Период
Сортировка
От marc_firth
Тема Re: Add quto increment to existing column
Дата
Msg-id 1317735533004-4868544.post@n5.nabble.com
обсуждение исходный текст
Ответ на Add quto increment to existing column  (Robert Buckley <robertdbuckley@yahoo.com>)
Ответы Re: Add quto increment to existing column
Список pgsql-general
If you use the SERIAL (this is the auto-incrementing function that creates
sequences in the bankground for you) datatype you can accomplish it in one
go.

So:
DROP sequence hist_id_seq;  -- Get rid of your old sequence

ALTER TABLE my_table DROP COLUMN hist_id; -- Remove id column

ALTER TABLE my_table ADD COLUMN hist_id SERIAL PRIMARY KEY; -- Recreate it
as Primary Key and quto-incrementing.

Btw:  have you tried the   http://www.pgadmin.org/ pgadmin  gui for
postgres?  It will help you do tasks like this and show you the SQL to do it
on the command line :)

Cheers,
Marc



Robert Buckley wrote:
>
> Hi,
>
> I have a column in a table called hist_id with the datatype "integer".
> When I created the table I assigned this column the primary 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;
>
> thanks for any help,
>
> Rob
>


--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Add-quto-increment-to-existing-column-tp4868404p4868544.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

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

Предыдущее
От: Craig Ringer
Дата:
Сообщение: Re: How can i get record by data block not by sql?
Следующее
От: Phil Couling
Дата:
Сообщение: Re: Add quto increment to existing column