Re: One sequence for different tables

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: <Robert(dot)Farrugia(at)go(dot)com(dot)mt>
Cc: <pgsql-admin(at)postgresql(dot)org>
Subject: Re: One sequence for different tables
Date: 2002-03-11 17:04:36
Message-ID: 20020311090350.B45259-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Mon, 11 Mar 2002 Robert(dot)Farrugia(at)go(dot)com(dot)mt wrote:

> Is it possible to create one sequence to be used for more than one table ?
> Let's say I create a pkey_seq sequence.
> Can I use it in table A (pkey default nextval('pkey_seq') PRIMARY KEY) and
> in table B as (pkey default nextval('pkey_seq') PRIMARY KEY) ?

Yes.

> Is it safe in that each table will have unique values i.e. if I have a
> third table C which is used to link data both from A and B using the pkey
> field, will there be records having the same pkey but from different
> tables?

As long as you never insert an explicit value into the column and don't
have to roll over the sequence, you should be safe.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Chad R. Larson 2002-03-11 18:16:57 Re: Postgres not starting at boot(FreeBSD) - startup
Previous Message Peter Eisentraut 2002-03-11 17:04:10 Re: One sequence for different tables