Re: auto_increment - Mailing list pgsql-general

From Fran Fabrizio
Subject Re: auto_increment
Date
Msg-id 3CC86B41.8050004@mmrd.com
Whole thread Raw
In response to auto_increment  (webmaster <webmaster@harbornet.com>)
List pgsql-general
Well, I suppose you could create a new sequence, set it's starting value
to be higher than any key in the PK field already, and add a default to
that column of nextval('my_new_seq').  The docs for 'create sequence'
should be a good place to start.

With a little extra elbow grease you can copy, drop and recreate the
table while massaging the existing PK's to start at 1 and count up, then
create the sequence as described above, if you really want an orderly PK
field.

-Fran

webmaster wrote:
> Does any one know if I can alter the primary key of a table to an
> integer that automatically increases each time a value is added?  Thanks
> for any help.  Or do I have to delete the table and create a new one?
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org



pgsql-general by date:

Previous
From: "Robert J. Sanford, Jr."
Date:
Subject: Re: odd psql behaviour on OSX
Next
From: rpetike@freemail.hu
Date:
Subject: large object dump-restore problem(bug?)