Re: Best way to create unique primary keys across schemas? - Mailing list pgsql-general

From Chris Angelico
Subject Re: Best way to create unique primary keys across schemas?
Date
Msg-id CAPTjJmqKRNBpPAh9PbwOAjhLYjyzThZ=t4bx1FOaZjQkO5o5=A@mail.gmail.com
Whole thread Raw
In response to Re: Best way to create unique primary keys across schemas?  (panam <panam@gmx.net>)
Responses Re: Best way to create unique primary keys across schemas?  (panam <panam@gmx.net>)
List pgsql-general
On Wed, Jan 25, 2012 at 9:54 AM, panam <panam@gmx.net> wrote:
> What do you mean with "explicit sequence object"? An own sequence for each
> table per schema?

This:

On Wed, Jan 25, 2012 at 10:23 AM, Merlin Moncure <mmoncure@gmail.com> wrote:
> Barring domains, you can just manually apply the default instead of
> using a serial type:
>
> create table foo (gid bigint default nextval('global_seq'));

http://www.postgresql.org/docs/9.1/static/sql-createsequence.html

When you create a 'serial' column, Postgres creates a sequence and
makes the column as 'int' with a default that pulls from the sequence.
(Similarly for 'bigserial' and 'bigint'.) If you create the sequence
yourself, you get a bit more control over it (eg setting
min/max/step), and can name it appropriately.

Note the OWNED BY clause (as documented in the above link). That's
what I was saying about the sequence being owned by or linked to the
creating table.

ChrisA

pgsql-general by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: any plans to support more rounding methods in sql?
Next
From: Jason Armstrong
Date:
Subject: Index on parent/child hierarchy