Database Reference
In-Depth Information
All of the arguments given in the CREATE TRIGGER statement are converted to
strings, and this includes any NULL values.
This means putting NULL in the argument list results in text NULL in the corres-
ponding slot in PG_ARGV .
Trigger on specific field changes
Another way of controlling when a trigger is fired is using a list of columns. In UPDATE
triggers, you can specify one or more comma-separated columns to tell PostgreSQL
that the trigger function should only be executed if any of the listed columns change.
It is possible to construct the same conditional expression with a WHEN clause, but
the list of columns has cleaner syntax:
WHEN(
NEW.column1 IS DISTINCT FROM OLD.column1
OR
NEW.column2 IS DISTINCT FROM OLD.column2)
A common example of how this conditional expression is used is raising an error
each time someone tries to change a primary key column. This can easily be done
by declaring an AFTER trigger using the cancel_op() trigger function (defined pre-
viously in this chapter) as follows:
CREATE TRIGGER disallow_pk_change
AFTER UPDATE OF id ON table_with_pk_id
FOR EACH ROW
EXECUTE PROCEDURE cancel_op();
Search WWH ::




Custom Search