Received: from smtp4.mail.yahoo.com (smtp4.mail.yahoo.com [128.11.69.101]) by mail.postgresql.org (8.11.1/8.11.1) with SMTP id f18B4mx89929 for ; Thu, 8 Feb 2001 06:04:48 -0500 (EST) (envelope-from janwieck@yahoo.com) Received: from a61a4.pppool.de (HELO jupiter.greatbridge.com) (213.6.97.164) by smtp.mail.vip.suc.yahoo.com with SMTP; 8 Feb 2001 11:04:44 -0000 X-Apparently-From: Received: (from janwieck@localhost) by jupiter.greatbridge.com (8.9.3/8.9.3) id FAA02777; Thu, 8 Feb 2001 05:59:12 -0500 From: Jan Wieck Message-Id: <200102081059.FAA02777@jupiter.greatbridge.com> Subject: Re: Is this a bug, or is it just me? In-Reply-To: from Josh Berkus at "Feb 6, 2001 08:15:35 pm" To: Josh Berkus Date: Thu, 8 Feb 2001 05:59:12 -0500 (EST) CC: sqllist X-Mailer: ELM [version 2.4ME+ PL68 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200102/150 X-Sequence-Number: 1330 Josh Berkus wrote: > Tom et al. > > Discovered this quirk in foriegn keys: > > In the preliminary version of a database, I added foriegn > key constraints to a number of tables, linking them to a > column in a shared reference table (status.status) that was > only one-half of a composite primary key (and thus the > values were not unique). When I tried to delete a row > containing a "2" in the status column from the status > relation, I received a Foreign Key violation error event > though there were other "2"'s in the table still present. > > So ... is this a bug in forign key implementation, or just > my fault for keying off a non-unique value? > > And, if the latter, is there a way I can construct a foreign > key constraint that keys onto a view or query? The referenced columns of a foreign key constraint shall have a unique constraint. That's how it is in the SQL specs. So it is a bug that the system let's you specify the constraint at all. I think Stephan fixed it for 7.1. OTOH Postgres doesn't (and shouldn't) enforce it after, because if it would, you couldn't drop/create a corrupted index. And no, you can't actually reference to a view or anything else than a table. That is, because the system wouldn't know how to check for the DELETE/UPDATE cases on the base tables building the view if the removal of a key would violate existing references. For such custom setups, we have procedural languages and triggers. Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com # _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com