The REFERENCING clause

A statement trigger can see the whole result set of the affected tuples. We can think of it as two result sets made of NEW and OLD tuples. This is particularly useful because it allows the trigger function to have a look at the so called transitional table, which is a pseudo-table made by the result set of incoming changes.

Transitional tables are made aliases via the REFERENCING clause, followed by NEW TABLE AS and OLD TABLE AS for the incoming and old tuples respectively. Inside the trigger function, these result sets are managed as regular tables. As in the case of NEW and OLD record aliases, NEW TABLE and OLD TABLE are not always available. For INSERT, only NEW TABLE can be aliased, while for UPDATE, both can be ...

Get PostgreSQL 11 Server Side Programming Quick Start Guide 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.