X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 8E8A69FA4AE for ; Sun, 17 Sep 2006 09:32:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 07696-10 for ; Sun, 17 Sep 2006 12:32:15 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from obelix.askesis.nl (laudanum.demon.nl [82.161.125.16]) by postgresql.org (Postfix) with ESMTP id 84F729FA45F for ; Sun, 17 Sep 2006 09:32:14 -0300 (ADT) Received: obelix 172.31.0.1 from 172.31.1.1 172.31.1.1 via HTTP with MS-WebStorage 6.0.6249 Received: from panoramix by obelix; 17 Sep 2006 14:32:11 +0200 Subject: Transactional behaviour with trigger From: Joost Kraaijeveld To: pgsql-sql@postgresql.org Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Sun, 17 Sep 2006 14:32:10 +0200 Message-Id: <1158496330.6107.17.camel@panoramix> Mime-Version: 1.0 X-Mailer: Evolution 2.6.3 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.136 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, UNPARSEABLE_RELAY X-Spam-Level: X-Archive-Number: 200609/116 X-Sequence-Number: 26327 Hi, I create two records in a transaction in two different tables: customer and contactaddress. customer has a foreign key to contactaddress. I also have third table, customeraddress, which is a materialized view of the join of customer and contactaddress For the table customer I have a trigger(function) that inserts a record in this third table (which works OK as the record is added): .... INSERT INTO customeraddress(customer, customernumber, lastname, zipcode, city,housenumber, address) VALUES(NEW.objectid,NEW.customernumber,NEW.lastname,NULL,NULL,NULL,NULL); For the contactaddress I also have a trigger(function) that should update the record in the third table with the additional info of the contactaddress: .... SELECT INTO customer_record objectid FROM prototype.customers WHERE contactaddress = NEW.objectid; IF customer_record.objectid IS NOT NULL THEN UPDATE customeraddress set zipcode = NEW.zipcode, city = NEW.city, housenumber = NEW.housenumber , address = NEW.objectid WHERE customer = customer_record.objectid; This last trigger is executed but customer_record.objectid seems to be always NULL as if the the customer record is not visible. Is that correct or is there something wrong with the SQl above? In other words: 1. start transaction 2. add customer record 3. fire customer insert trigger -> copy record to materialized view table 4. add contactaddress record 5. fire contactaddress insert trigger -> update record in materialized view table -> no customer record??? 6. end transction TIA -- Groeten, Joost Kraaijeveld Askesis B.V. Molukkenstraat 14 6524NB Nijmegen tel: 024-3888063 / 06-51855277 fax: 024-3608416 web: www.askesis.nl