pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedOne sequence for different tables
5+ messages / 5 participants
[nested] [flat]
* One sequence for different tables
@ 2002-03-11 14:20 Robert.Farrugia@go.com.mt
0 siblings, 3 replies; 5+ messages in thread
From: Robert.Farrugia@go.com.mt @ 2002-03-11 14:20 UTC (permalink / raw)
To: pgsql-admin
Hi,
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) ?
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?
Thanks alot
Robert
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: One sequence for different tables
@ 2002-03-11 16:56 Bruno Wolff III <bruno@wolff.to>
parent: Robert.Farrugia@go.com.mt
2 siblings, 0 replies; 5+ messages in thread
From: Bruno Wolff III @ 2002-03-11 16:56 UTC (permalink / raw)
To: Robert.Farrugia@go.com.mt; +Cc: pgsql-admin
On Mon, Mar 11, 2002 at 03:20:35PM +0100,
Robert.Farrugia@go.com.mt wrote:
> Hi,
>
> 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) ?
> 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?
The sequence values will be unique accross tables when doing things this way.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: One sequence for different tables
@ 2002-03-11 17:04 Peter Eisentraut <peter_e@gmx.net>
parent: Robert.Farrugia@go.com.mt
2 siblings, 0 replies; 5+ messages in thread
From: Peter Eisentraut @ 2002-03-11 17:04 UTC (permalink / raw)
To: Robert.Farrugia@go.com.mt; +Cc: pgsql-admin
Robert.Farrugia@go.com.mt writes:
> Is it possible to create one sequence to be used for more than one table ?
Yes.
> 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) ?
Just like that.
> 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?
The sequence-generated numbers will be unique across A and B. But I doubt
that that system is a good design.
--
Peter Eisentraut peter_e@gmx.net
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: One sequence for different tables
@ 2002-03-11 17:04 Stephan Szabo <sszabo@megazone23.bigpanda.com>
parent: Robert.Farrugia@go.com.mt
2 siblings, 1 reply; 5+ messages in thread
From: Stephan Szabo @ 2002-03-11 17:04 UTC (permalink / raw)
To: Robert.Farrugia@go.com.mt; +Cc: pgsql-admin
On Mon, 11 Mar 2002 Robert.Farrugia@go.com.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.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: One sequence for different tables
@ 2002-03-12 03:52 Brian McCane <bmccane@mccons.net>
parent: Stephan Szabo <sszabo@megazone23.bigpanda.com>
0 siblings, 0 replies; 5+ messages in thread
From: Brian McCane @ 2002-03-12 03:52 UTC (permalink / raw)
To: pgsql-admin
On Mon, 11 Mar 2002, Stephan Szabo wrote:
You can add a trigger, BEFORE INSERT on each table to check the key in the
other table to prevent cross table duplications. I have done this in the
past, but I no longer do. It didn't work as well as I intended. I also
occasionally got duplicates anyway, which I could never explain. But that
was way back on a 6.? server I used to have.
- brian
> On Mon, 11 Mar 2002 Robert.Farrugia@go.com.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.
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
Wm. Brian McCane | Life is full of doors that won't open
Search http://recall.maxbaud.net/ | when you knock, equally spaced amid those
Usenet http://freenews.maxbaud.net/ | that open when you don't want them to.
Auction http://www.sellit-here.com/ | - Roger Zelazny "Blood of Amber"
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2002-03-12 03:52 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-03-11 14:20 One sequence for different tables Robert.Farrugia@go.com.mt
2002-03-11 16:56 ` Bruno Wolff III <bruno@wolff.to>
2002-03-11 17:04 ` Peter Eisentraut <peter_e@gmx.net>
2002-03-11 17:04 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2002-03-12 03:52 ` Brian McCane <bmccane@mccons.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox