How to apply a update after an inser or update POSTGRESQL Trigger
Posted
by
user3718906
on Stack Overflow
See other posts from Stack Overflow
or by user3718906
Published on 2014-06-08T03:14:49Z
Indexed on
2014/06/08
3:24 UTC
Read the original article
Hit count: 165
How to apply an update after an insert or update in POSTGRESQL;
I have got a table which has a field lastupdate;
I want that field to be set up whenever the row is updated or when it was inserted.
I tried this trigger, but It is not working! HELP!!
CREATE OR REPLACE FUNCTION fn_update_profile()
RETURNS TRIGGER AS $update_profile$
BEGIN
IF (TG_OP = 'INSERT' OR TG_OP = 'UPDATE' ) THEN
UPDATE profile SET lastupdate=now() where oid=OLD.oid;
RETURN NULL;
ELSEIF (TG_OP = 'DELETE') THEN
RETURN NULL;
END IF;
RETURN NULL; -- result is ignored since this is an AFTER trigger
END;
$update_profile$ LANGUAGE plpgsql;
© Stack Overflow or respective owner