X-Original-To: pgsql-general@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E373C476584 for ; Thu, 15 May 2003 02:43:23 -0400 (EDT) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with ESMTP id 16320-01 for ; Thu, 15 May 2003 02:43:22 -0400 (EDT) Received: from starboard.anchor.net.au (starboard.anchor.net.au [203.98.94.10]) by postgresql.org (Postfix) with ESMTP id 73EDB475CEE for ; Thu, 15 May 2003 02:43:21 -0400 (EDT) Received: from pirate.bridge.anchor.net.au (syd.harbour.anchor.net.au [203.98.86.1]) by starboard.anchor.net.au (8.11.6/8.11.6) with ESMTP id h4F6NDP13339; Thu, 15 May 2003 16:23:13 +1000 Subject: Re: table inheritance and foreign keys From: James Gregory To: Reece Hart Cc: pgsql-general@postgresql.org In-Reply-To: <1052957276.5829.53.camel@tallac> References: <1052957276.5829.53.camel@tallac> Content-Type: text/plain Message-Id: <1052980983.5672.7.camel@pirate.bridge.anchor.net.au> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.3.2-1mdk (Preview Release) Date: 15 May 2003 16:43:04 +1000 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/503 X-Sequence-Number: 42158 On Thu, 2003-05-15 at 10:07, Reece Hart wrote: > I'd appreciate some advice regarding the use of foreign keys in > inherited tables. Specifically, here's the schema I'd like: Ok, you can't do it with native postgres RI stuff. I'm told that the subject has been debated extensively, but right now it can't be done. I had to do the same thing as you and the way I've gone about it is to write triggers in plpython that raise an exception if RI is not maintained. I have a table that lists all the "x references y" pairs, and it just reads that and does the query to see if it can find a row in the "y" table with the right ID. It was working quite well (within my limited testing) until I hit a but in plpython last night. Said bug is on my todo list to take a look at, but that won't be happening imediately. You'll find you can't write this stuff easily in plpgsql, and I don't recommend plpython right now because I don't trust it at this point. You might have some luck writing similar triggers in C. I'm happy to send you my python triggers if you'd like something to start from, but be warned: they're a bit of a mess. HTH James.