I’m a postgresql user and I’m trying to follow this :
http://www.postgresql.org/docs/current/interactive/sql-createtrigger.html
CREATE TRIGGER check_update
BEFORE UPDATE ON accounts
FOR EACH ROW
WHEN (OLD.balance IS DISTINCT FROM NEW.balance)
EXECUTE PROCEDURE check_account_update();
but with AFTER instead of BEFORE. and I’m keep getting error on or near WHEN.
does that because i have to use BEFORE ? what if i need to execute the procedure after updating column and it has really changed ?
PostgreSQL 8.4 doesn’t support WHEN with triggers, from the fine manual:
There is no WHEN there. You can put the WHEN logic inside your trigger function:
or upgrade to at least PostgreSQL 9.0 and use WHEN when creating the trigger.