Re: auto-increment column - Mailing list pgsql-general

From Joe Abbate
Subject Re: auto-increment column
Date
Msg-id 4E8B0199.6000203@freedomcircle.com
Whole thread Raw
In response to Re: auto-increment column  (Robert Buckley <robertdbuckley@yahoo.com>)
List pgsql-general
On 10/04/2011 08:05 AM, Robert Buckley wrote:
> Thanks for the replies,
>
> I have one question regarding this comment...
>
> "You also need to add a DEFAULT expression and optionally
> make the sequence owned by the column:"
>
> What difference does it make if a table "owns" a sequence of not?...does
> this contraint the use of the sequence to ONLY that one table?
>
> The sequence will only be used to auto-increment the id column in order
> to have an automatic primary key. Could I then somehow use the sequence
> for all tables which need this?

Making the table own the sequence causes the sequence to be dropped if
the table is dropped.  Making the sequence owned by the table happens
automatically if you had originally created the column with SERIAL
instead of adding the sequence with ALTER TABLE, but is not entirely
necessary.

That said, I'd think twice before using a sequence for more than one
table (unless they were part of an inheritance/partitioning scheme).

Joe

pgsql-general by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: Re: PG Source Compilation (Optional Features / Optional Packages)
Next
From: Craig Ringer
Date:
Subject: Re: How can i get record by data block not by sql?