Re: auto-increment column

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Robert Buckley <robertdbuckley(at)yahoo(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: auto-increment column
Date: 2011-10-04 11:37:09
Message-ID: 20111004113709.GA10419@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Oct 04, 2011 at 12:30:48PM +0100, 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;

alter table hist alter column hist_id set default nextval( 'hist_id_seq');

Best regards,

depesz

--
The best thing about modern society is how easy it is to avoid contact with it.
http://depesz.com/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Boszormenyi Zoltan 2011-10-04 11:43:07 Re: auto-increment column
Previous Message Robert Buckley 2011-10-04 11:30:48 auto-increment column