X-Original-To: pgsql-novice-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 417EBD1B183 for ; Mon, 2 Aug 2004 05:17:45 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 90356-02 for ; Mon, 2 Aug 2004 08:17:44 +0000 (GMT) Received: from mpls-qmqp-01.inet.qwest.net (mpls-qmqp-01.inet.qwest.net [63.231.195.112]) by svr1.postgresql.org (Postfix) with SMTP id DE508D1B181 for ; Mon, 2 Aug 2004 05:17:41 -0300 (ADT) Received: (qmail 9367 invoked by uid 0); 2 Aug 2004 08:17:43 -0000 Received: from unknown (63.231.195.5) by mpls-qmqp-01.inet.qwest.net with QMQP; 2 Aug 2004 08:17:43 -0000 Received: from 63-227-127-37.dnvr.qwest.net (HELO ?10.0.0.2?) (63.227.127.37) by mpls-pop-05.inet.qwest.net with SMTP; 2 Aug 2004 08:17:43 -0000 Date: Mon, 02 Aug 2004 02:19:03 -0600 Message-Id: <1091434743.27166.19.camel@localhost.localdomain> From: "Scott Marlowe" To: "Pradeepkumar, Pyatalo (IE10)" Cc: pgsql-novice@postgresql.org Subject: Re: Help on triggers In-Reply-To: <77ED2BF75D59D1439F90412CC5B109740FA2CD4D@ie10-sahara.hiso.honeywell.com> References: <77ED2BF75D59D1439F90412CC5B109740FA2CD4D@ie10-sahara.hiso.honeywell.com> Content-Type: text/plain Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200408/6 X-Sequence-Number: 10543 On Sun, 2004-08-01 at 23:27, Pradeepkumar, Pyatalo (IE10) wrote: > Hi all, > > I have 2 tables - table1 and table2. Both the tables are related to each > other. I have written triggers so that if a tuple is inserted into table1, > corresponding values will be inserted into table2. and if a tuple is deleted > from table1 then corresponding tuples are deleted from table2 also. The > delete trigger works fine sometimes and other times it gives the following > error..... > > delete from table1 where pointid=30; > ERROR: update or delete on "table1" violates foreign key constraint "$2" on > "table2" > DETAIL: key (pointid) =30 is still referenced from table "pointattributes". > > I am doing an application in C. I have written a C-function using libpq API > to delete a tuple from table1. that is I pass a parameter to the function > and it has to delete the tuple whose primarykey value= parameter and also > delete correspoding tuples from table2(due to the trigger). so i have formed > a simple delete command on table2in the C-function. When i compile the > application it gives the same error: > > is there anyone who can explain why this is happening. I had posted this > query 2 days back...dint get any reply. Please help me out with this. Using foreign keys, you should be able to just set the relation to cascade and have the dependent rows deleted automagically.