Setting NEW in AFTER trigger

From: Robert Fitzpatrick <lists(at)webtent(dot)net>
To: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Setting NEW in AFTER trigger
Date: 2008-12-15 16:32:39
Message-ID: 1229358759.10857.48.camel@columbus.webtent.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is it not possible to set the value of a field by reference of NEW.field
in an AFTER trigger? I have a trigger where I set NEW.field :=
myfunction and NEW.field shows the resulting value in my RAISE NOTICE as
shown here...

CREATE OR REPLACE FUNCTION "public"."registrants_tr_test_func" () RETURNS trigger AS
$body$
BEGIN
NEW.egw_id := egw_add_account(NEW.id);
RAISE NOTICE 'TEST: %', NEW.egw_id;
RETURN NEW;
END;
$body$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100;
CREATE TRIGGER "registrants_tr_test" AFTER UPDATE
ON "public"."registrants" FOR EACH ROW
EXECUTE PROCEDURE "public"."registrants_tr_test_func"();

update registrants set registrant_email = 'lists(at)webtent(dot)net' where id = 14135;
NOTICE: Groupware user already exists: 3058
CONTEXT: PL/pgSQL function "registrants_tr_test_func" line 2 at assignment
NOTICE: TEST: 3058

maxegen=> SELECT public.registrants.egw_id FROM public.registrants WHERE public.registrants.id = 14135;
egw_id
--------

(1 row)

The Groupware NOTICE is output from the function if a lookup is found
and returns the existing id in place of an INSERT with the new id
returned if not found. I get no errors, but NEW.field remains NULL after
updating the record as shown above. Hopefully I'm doing something wrong?

--
Robert

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jonathon Suggs 2008-12-15 16:40:34 Re: Query Question (one group by vs two separate)
Previous Message Ivan Sergio Borgonovo 2008-12-15 16:32:04 [SOLVED] Re: from 2 keys to serial