Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 41DC72E3CD3 for ; Wed, 12 Dec 2007 17:38:22 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 63159-01-10 for ; Wed, 12 Dec 2007 17:38:04 -0400 (AST) Received: from smtp04.itc.nl (smtp04.itc.nl [192.87.16.34]) by postgresql.org (Postfix) with ESMTP id 164552E36AF for ; Wed, 12 Dec 2007 17:38:09 -0400 (AST) Received: from itcnt09.itc.nl (Not Verified[172.16.2.9]) by smtp04.itc.nl with MailMarshal (v6, 2, 2, 3503) id ; Wed, 12 Dec 2007 22:38:07 +0100 Received: from [192.168.1.100] ([217.123.141.251]) by itcnt09.itc.nl with Microsoft SMTPSVC(6.0.3790.3959); Wed, 12 Dec 2007 22:38:06 +0100 Message-ID: <476054C8.80001@itc.nl> Date: Wed, 12 Dec 2007 22:38:16 +0100 From: "Rolf A. de By" Organization: ITC User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Trigger definition . . . puzzled Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 12 Dec 2007 21:38:06.0873 (UTC) FILETIME=[48656890:01C83D07] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/75 X-Sequence-Number: 29767 Greetings list, Running pg 8.2.3. on a windows machine, I have become blind in a trigger definition puzzle, so hope that somebody may help me understand where I goof. I have a base table i_s that has three tables that inherit from it, one of them being i_s_nowhere. The base table should be left empty, but I want it to be the prime port of call for data changes. Hence the following set-up. Let me try to be brief, in the hope of not leaving out relevant detail. Base table def is as follows: CREATE TABLE i_s ( sidx integer NOT NULL, -- The s identifier gid integer NOT NULL, -- The i identifier status character(1), confirmation character(1), CONSTRAINT pk_is PRIMARY KEY (sidx, gid) ) WITH (OIDS=FALSE); And the trigger definition is here: CREATE TRIGGER aw_archival_is2 BEFORE UPDATE OR INSERT OR DELETE ON i_s FOR EACH ROW EXECUTE PROCEDURE aw_archive_test(); And the trigger function: CREATE OR REPLACE FUNCTION aw_archive_test() RETURNS "trigger" AS $BODY$ BEGIN RAISE WARNING 'Starting isa trigger for %', TG_OP; IF (TG_OP = 'UPDATE') THEN RAISE WARNING 'Calling insert_isa with update'; ELSIF (TG_OP = 'INSERT') THEN RAISE WARNING 'Calling insert_isa with insert'; ELSIF (TG_OP = 'DELETE') THEN RAISE WARNING 'Calling insert_isa with delete'; END IF; RETURN NULL; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE; The trigger is enabled. Yes, this does intentionally nothing. The real code will obviously take care of data change in proper subtables. Well, the trigger should do nothing now . . . What I cannot get round to understanding is that an insert attempt will nicely give me two warnings, and will not insert, as expected with this code: WARNING: Starting isa trigger for INSERT WARNING: Calling insert_isa with insert Query returned successfully: 0 rows affected, 31 ms execution time. But an attempt to update actually magically goes to the proper subtable and performs the update: Query returned successfully: 1 rows affected, 16 ms execution time. Where did I deserve this?? ;-) In attempts to solve this I did mess around with trigger and trigger function definitions a bit. Could there be funny traces of this? What is the best way to analyse this behavior? I am testing from a pgAdmin 1.8 setup. All suggestions welcome! -- Rolf A. de By The Netherlands