In PostgreSQL, the keyword ALSO appears only inside CREATE RULE statements. A rule can either replace the triggering command (using INSTEAD) or supplement it (using ALSO). When DO ALSO is specified, PostgreSQL runs the original user statement first, then executes the rule’s action list. If DO ALSO is omitted, PostgreSQL assumes DO ALSO by default, but stating it explicitly makes intent clear and improves readability. Rules fire at the statement level, so DO ALSO actions run once per statement, not once per row. Rules are processed before triggers, which can affect side-effect ordering. Because rules rewrite queries, pay attention to possible performance impacts and to the fact that rule actions execute with the same privileges as the original statement.
CREATE RULE, DO INSTEAD, TRIGGER, RULE system, Query rewriting
PostgreSQL 7.0
DO ALSO rules are evaluated during the query rewrite phase. They can add statements (like logging inserts) without invoking per-row overhead, making them efficient for statement-level side effects.
The original statement runs first. PostgreSQL then executes the DO ALSO action list within the same transaction.
No. A single rule can specify either INSTEAD or ALSO, not both. Create separate rules if you need different behaviors for different conditions.
Run DROP RULE rule_name ON table_name; to remove the rule. This stops the associated DO ALSO actions from executing.