Re: alter integer field to serial integer primary key

From: Adrian Klaver <aklaver(at)comcast(dot)net>
To: pgsql-general(at)postgresql(dot)org
Cc: rloefgren(at)forethought(dot)net
Subject: Re: alter integer field to serial integer primary key
Date: 2006-09-30 20:49:08
Message-ID: 200609301349.08403.aklaver@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Friday 29 September 2006 09:51 am, rloefgren(at)forethought(dot)net wrote:
> I have an integer field of unique, consecutive numbers. Can I change
> this to be a serial, primary key field using an ALTER TABLE ALTER
> COLUMN command? I haven't been able to stumble over it.
>
> thanks,
>
> r
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org

I think the easiest way would be to use CREATE SEQUENCE to create a sequence
with a start value above that of max(integer field) and then use ALTER TABLE
to set the nextval(sequence) as the DEFAULT value.
--
Adrian Klaver
aklaver(at)comcast(dot)net

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-09-30 20:49:31 Re: Strange pg_ctl behavior: postmaster shuts down on shell interrupt
Previous Message Tom Lane 2006-09-30 19:16:56 Re: Potentially annoying question about date ranges