Creating Custom Rules

Rules are very similar to triggers in concept, with some crucial differences. Triggers usually refer exclusively to the table being acted on, whereas rules act on external tables. Additionally, triggers are fired in addition to the action being carried out. For instance, an INSERT trigger will fire the event either before or after the insert is performed.

Rules, on the other hand, can also be created with the optional keyword INSTEAD. In this case, the rule action is carried out in lieu of the specified action.

A typical use of rules is to perform actions on external tables when a table-related event occurs on the specified table. A simple use of a rule set would be to implement the capability to log an audit trail of changes ...

Get PostgreSQL Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.