Re: Inheritance and shared sequence

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: Sebastjan Trepca <trepca(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Inheritance and shared sequence
Date: 2007-06-07 20:33:59
Message-ID: 1181248439.32633.15.camel@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 2007-06-07 at 09:44 +0100, Richard Huxton wrote:
> Sebastjan Trepca wrote:
> > Hi,
> >
> > as I understood, when you create a table which inherits some other
> > table, the constraints and indexes do not go to the child table hence
> > you have to create a separate ones in there. That means you cannot
> > depend that you won't have duplicate IDs in both tables. Right?
> >
> > BUT...what if child table and parent table both use the same sequence
> > for the primary key. Would the duplication still be an issue?
>
> Well, if you *always* use the sequence you'll be OK (until you run out
> of numbers), but it won't stop you manually supplying your own values.

If you must keep the primary key unique across a set of tables, you need
to create another table to index the keys and record which table each
key is in. Use triggers to keep the index table up to date.
--
Oliver Elphick olly(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
Do you want to know God? http://www.lfix.co.uk/knowing_god.html

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Oliver Elphick 2007-06-07 20:38:41 Re: Suppress checking of chmod 700 on data-dir?
Previous Message Richard P. Welty 2007-06-07 20:03:37 Re: Creditcard Number Security was Re: Encrypted column