X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id E5234D1B523 for ; Thu, 30 Oct 2003 11:30:16 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 39647-01 for ; Thu, 30 Oct 2003 07:29:48 -0400 (AST) Received: from woodfire (ip-a1-37118.keycomm.it [62.152.37.118]) by svr1.postgresql.org (Postfix) with ESMTP id BB4F1D1B555 for ; Thu, 30 Oct 2003 07:29:41 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by woodfire (Postfix) with ESMTP id 6338FB4B for ; Thu, 30 Oct 2003 13:30:22 +0100 (CET) Received: from woodfire ([127.0.0.1]) by localhost (woodfire [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 00559-06 for ; Thu, 30 Oct 2003 13:30:11 +0100 (CET) Received: from osts (unknown [192.168.100.27]) by woodfire (Postfix) with ESMTP id 235B79DC for ; Thu, 30 Oct 2003 13:30:11 +0100 (CET) Subject: Bug in Rule+Foreing key constrain? From: Michele Bendazzoli To: pgsql-sql Content-Type: text/plain Organization: Micky Mouse Message-Id: <1067517334.2371.26.camel@mickymouse.sintel> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 Date: Thu, 30 Oct 2003 13:35:34 +0100 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at sintelnet.it X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/396 X-Sequence-Number: 15796 I have found a strange behaviour that I don't know if is a bug or not. I have three tables: * abilitazione with a primary key of (comuneid, cassonettoid, chiaveid) * cassonetto with a primary key of (comuneid, cassonettoid) * chiave with a primary key of (comuneid, chiaveid) and two foreign key from abilitazioni to cassonetto and chiave tables respectivly. Here is the picture (I hope it will be clear) cassonetto abilitazioni chiave |comuneid |--> |comuneid |<---|comuneid| PK -> |cassonettoid|--> |cassonettoid| | | |chiaveid |<---|chiaveid| |abilitata | Whenever I try to insert a row in abilitazione that hasn't a match row in cassonetto or abilitazione, an exception is raised (referential integrity violation : key referenced from abilitazione not found in cassonetto). So far, so good. Now if I Add a rule to abilitazione in order to avoid a duplication of a row when a user try to insert one with an existing primary key: CREATE OR REPLACE RULE abilita_ins_rl AS ON INSERT TO abilitazione WHERE (EXISTS ( SELECT 1 FROM abilitazione WHERE (((abilitazione.comuneid = new.comuneid ) AND (abilitazione.cassonettoid = new.cassonettoid )) AND (abilitazione.chiaveid = new.chiaveid )))) DO INSTEAD UPDATE abilitazione SET abilitata = new.abilitata WHERE (((abilitazione.comuneid = new.comuneid ) AND (abilitazione.cassonettoid = new.cassonettoid )) AND (abilitazione.chiaveid = new.chiaveid )); the constraints related to the foreign kesy disappears (i.e. I'm able to insert a row in abilitazioni that hasn't a key referenced in cassonetto or abilitazioni). Is this a bug or a feauture? If is a feature, it is possible to abilitate again the check of the contraints? Thank you in advance for any advice. ciao, Michele