In addition to features of PostgreSQL, triggers can be created with DO option.
Synopsis
CREATE [ OR REPLACE ] [ CONSTRAINT ] TRIGGER name { BEFORE | AFTER | INSTEAD OF } { event [ OR ... ] }
ON table_name
[ FROM referenced_table_name ]
[ NOT DEFERRABLE | [ DEFERRABLE ] [ INITIALLY IMMEDIATE | INITIALLY DEFERRED ] ]
[ REFERENCING { { OLD | NEW } TABLE [ AS ] transition_relation_name } [ ... ] ]
[ FOR [ EACH ] { ROW | STATEMENT } ]
[ WHEN ( condition ) ]
{ EXECUTE { FUNCTION | PROCEDURE } function_name ( arguments )
| DO [ LANGUAGE lang_name ] code }
Description
Refer to the PostgreSQL Documentation for information about CREATE TRIGGER. This section describes DO option.
A trigger which is created with DO option will be associated with the specified table or view and will execute the specified code by the specified procedural language of DO (unnamed code block) when certain events occur.
Parameters
The name of the language that the function is implemented in.
plpgsql is supported in CREATE TRIGGER.
When the certain events occur, it executes the code in a specified procedural language. The unnamed code block does not require a prior definition like a function. Syntax is same as procedural language.
Note
A trigger defined with DO option cannot be replaced by a trigger defined with EXECUTE PROCEDURE option.
A trigger defined with EXECUTE PROCEDURE option cannot be replaced by a trigger defined with DO option.
Examples
It executes the code block that is specified by DO before the table is updated.
(Example that LANGUAGE is plpgsql)
CREATE TRIGGER check_update BEFORE UPDATE ON accounts FOR EACH ROW DO $$BEGIN RETURN NEW; END;$$ ;
Information
When a trigger created with DO option, a new function is created internally. The name of function is "schema name"."on table name"_"trigger name"_TRIGPROC(serial number).