Re: auto-increment column

From: Joe Abbate <jma(at)freedomcircle(dot)com>
To: Robert Buckley <robertdbuckley(at)yahoo(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: auto-increment column
Date: 2011-10-04 12:52:41
Message-ID: 4E8B0199.6000203@freedomcircle.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2011-10-04 13:04:21 Re: How can i get record by data block not by sql?
Previous Message hubert depesz lubaczewski 2011-10-04 12:36:23 Re: PG Source Compilation (Optional Features / Optional Packages)