Offer triggers on foreign tables.
Noah Misch <noah@leadboat.com>
Offer triggers on foreign tables. This covers all the SQL-standard trigger types supported for regular tables; it does not cover constraint triggers. The approach for acquiring the old row mirrors that for view INSTEAD OF triggers. For AFTER ROW triggers, we spool the foreign tuples to a tuplestore. This changes the FDW API contract; when deciding which columns to populate in the slot returned from data modification callbacks, writable FDWs will need to check for AFTER ROW triggers in addition to checking for a RETURNING clause. In support of the feature addition, refactor the TriggerFlags bits and the assembly of old tuples in ModifyTable. Ronan Dunklau, reviewed by KaiGai Kohei; some additional hacking by me.
Files
| Path | Change | +/− |
|---|---|---|
| contrib/postgres_fdw/deparse.c | modified | +37 −26 |
| contrib/postgres_fdw/expected/postgres_fdw.out | modified | +319 −0 |
| contrib/postgres_fdw/postgres_fdw.c | modified | +2 −2 |
| contrib/postgres_fdw/sql/postgres_fdw.sql | modified | +216 −0 |
| doc/src/sgml/fdwhandler.sgml | modified | +20 −16 |
| doc/src/sgml/ref/create_trigger.sgml | modified | +26 −17 |
| doc/src/sgml/trigger.sgml | modified | +14 −11 |
| src/backend/commands/tablecmds.c | modified | +3 −0 |
| src/backend/commands/trigger.c | modified | +340 −83 |
| src/backend/executor/nodeModifyTable.c | modified | +52 −38 |
| src/backend/rewrite/rewriteHandler.c | modified | +29 −7 |
| src/include/commands/trigger.h | modified | +6 −2 |
| src/test/regress/expected/foreign_data.out | modified | +37 −0 |
| src/test/regress/sql/foreign_data.sql | modified | +44 −0 |