Received: from cobalt.rmnet.it (cobalt.rmnet.it [194.183.26.12]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f9MLQ5P17969; Mon, 22 Oct 2001 17:26:05 -0400 (EDT) (envelope-from san@cobalt.rmnet.it) Received: (from san@localhost) by cobalt.rmnet.it (8.9.3/8.9.3) id XAA30632; Mon, 22 Oct 2001 23:25:44 +0200 Date: Mon, 22 Oct 2001 23:25:44 +0200 Message-Id: <200110222125.XAA30632@cobalt.rmnet.it> From: san@cobalt.rmnet.it To: pgsql-hackers@postgresql.org, pgsql-sql@postgresql.org, pgsql-novice@postgresql.org Subject: PL/pgSQL triggers ON INSERT OR UPDATE X-Mailer: |sed && vi X-Archive-Number: 200110/139 X-Sequence-Number: 2243 Hello, I'm trying to set up a trigger on insert or update but when using the predefined variable ``OLD'' I get a NOTICE from the trigger function about OLD not being defined yet. Of course OLD is not defined when the function is triggered on INSERT event, and I did not mention it if not inside a conditional block checking for the TG_OP variable being 'UPDATE'. For better understanding here is some code: BEGIN IF TG_OP = 'UPDATE' THEN IF OLD.id <> NEW.id THEN -- do the work END IF END IF; END; Even when TG_OP != 'UPDATE' (INSERT event) I still get an error message from the pl/pgsql compiler (the first time the trigger is fired). What should I do then ? Is it still possible to use the same function for UPDATE OR INSERT events ? TIA --san;