Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: alter integer field to serial integer primary key



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



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group