|
From: <ja...@op...> - 2001-03-05 19:41:42
|
Hey All,
Since I've included a last_updated and last_updated_user column in
most tables in the DB, I've investigated the use of triggers to
automatically set those columns on INSERT's and UPDATE's.
Turns out there is an example of how to do this in the Pg User Guide,
and it works quite nicely:
CREATE FUNCTION stamp () RETURNS OPAQUE AS '
BEGIN
NEW.last_updated := ''now'';
NEW.last_user := getpgusername();
RETURN NEW;
END;
' LANGUAGE 'plpgsql';
CREATE TRIGGER tst BEFORE INSERT OR UPDATE ON tst
FOR EACH ROW EXECUTE PROCEDURE stamp();
jas.
|