Re: auto_increment

From: Fran Fabrizio <ffabrizio(at)mmrd(dot)com>
To:
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: auto_increment
Date: 2002-04-25 20:46:57
Message-ID: 3CC86B41.8050004@mmrd.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message rpetike 2002-04-25 21:06:53 large object dump-restore problem(bug?)
Previous Message Robert J. Sanford, Jr. 2002-04-25 20:41:02 Re: odd psql behaviour on OSX