From: James Gregory <james@anchor.net.au>
To: Reece Hart <rkh@gene.COM>
Cc: pgsql-general@postgresql.org
Subject: Re: table inheritance and foreign keys
Date: 19 May 2003 12:15:37 +1000
Message-ID: <1053310536.5667.87.camel@pirate.bridge.anchor.net.au> (raw)
In-Reply-To: <1053102193.5829.1022.camel@tallac>
References: <1052957276.5829.53.camel@tallac>
<1052980983.5672.7.camel@pirate.bridge.anchor.net.au>
<1053102193.5829.1022.camel@tallac>
On Sat, 2003-05-17 at 02:23, Reece Hart wrote:
> James-
>
> Thanks for your advice. I think I'll opt for the following approach
> instead, but I'm interested to hear of any pitfalls you foresee.
>
> Subtables (for which I wanted to use inherit) will instead contain only
> the subtable-specific columns, and in addition contain a foreign key
> into the parent table. A view with insert, update, and delete rules can
> emulate the appearance of a full subtable (ie, inherited and
> subtable-specific columns).
>
> The upside I see over triggers is that the referential integrity is
> still on postgresql's back. The downside is that I end up with more
> tables and views to maintain and an extra join in many cases.
Heh, that's quite clever. I must admit I didn't even consider that.
You're right about it requiring lots of views, but my solution requires
lots of triggers. There's not much difference there, but it's more
visible when you forget to make a view - if I forget a trigger I
probably won't see it until the next audit of the database. I decided to
chase the "real inheritance" angle rather than looking for alternatives
such as this because I figured it was likely to be more future
compatible - I was hoping that either the postgres developers would add
inherited RI functionality or I would get time to implement it myself
(which I started doing). Of course, the RI in place atm is done with
triggers, so a C module to do it, along with some clever code to
actually add the triggers would allow it to live in contribs and not
sacrifice too much convenience.
>
> Again, thanks for your advice. Do you see any reason that the above
> sketch wouldn't work to emulate foreign keys into inherited tables?
I think it's a good way to proceed with the current version of
postgresql.
James.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: james@anchor.net.au, rkh@gene.COM
Subject: Re: table inheritance and foreign keys
In-Reply-To: <1053310536.5667.87.camel@pirate.bridge.anchor.net.au>
References: <1052957276.5829.53.camel@tallac> <1052980983.5672.7.camel@pirate.bridge.anchor.net.au> <1053102193.5829.1022.camel@tallac> <1053310536.5667.87.camel@pirate.bridge.anchor.net.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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