Support triggers on views.

Tom Lane <tgl@sss.pgh.pa.us>

Commit: 2ec993a7cbdd8e251817ac6bbc9a704ce8346f73
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: 2010-10-10T17:45:07Z
Releases: 9.1.0
Support triggers on views.

This patch adds the SQL-standard concept of an INSTEAD OF trigger, which
is fired instead of performing a physical insert/update/delete.  The
trigger function is passed the entire old and/or new rows of the view,
and must figure out what to do to the underlying tables to implement
the update.  So this feature can be used to implement updatable views
using trigger programming style rather than rule hacking.

In passing, this patch corrects the names of some columns in the
information_schema.triggers view.  It seems the SQL committee renamed
them somewhere between SQL:99 and SQL:2003.

Dean Rasheed, reviewed by Bernd Helmle; some additional hacking by me.

Files

PathChange+/−
doc/src/sgml/catalogs.sgml modified +5 −4
doc/src/sgml/information_schema.sgml modified +45 −16
doc/src/sgml/plperl.sgml modified +3 −1
doc/src/sgml/plpgsql.sgml modified +101 −5
doc/src/sgml/plpython.sgml modified +10 −10
doc/src/sgml/pltcl.sgml modified +10 −6
doc/src/sgml/ref/create_rule.sgml modified +6 −4
doc/src/sgml/ref/create_trigger.sgml modified +94 −12
doc/src/sgml/rules.sgml modified +106 −56
doc/src/sgml/trigger.sgml modified +107 −33
src/backend/catalog/index.c modified +1 −1
src/backend/catalog/information_schema.sql modified +28 −10
src/backend/catalog/sql_features.txt modified +1 −1
src/backend/commands/copy.c modified +1 −1
src/backend/commands/tablecmds.c modified +3 −3
src/backend/commands/trigger.c modified +338 −239
src/backend/executor/execMain.c modified +37 −7
src/backend/executor/nodeModifyTable.c modified +323 −176
src/backend/nodes/copyfuncs.c modified +1 −1
src/backend/nodes/equalfuncs.c modified +1 −1
src/backend/optimizer/prep/preptlist.c modified +8 −42
src/backend/parser/gram.y modified +10 −9
src/backend/rewrite/rewriteHandler.c modified +189 −63
src/backend/rewrite/rewriteManip.c modified +1 −1
src/backend/utils/adt/ruleutils.c modified +6 −1
src/bin/pg_dump/pg_dump.c modified +10 −2
src/bin/psql/describe.c modified +19 −4
src/include/catalog/catversion.h modified +1 −1
src/include/catalog/pg_trigger.h modified +29 −2
src/include/commands/trigger.h modified +36 −22
src/include/nodes/parsenodes.h modified +3 −2
src/include/utils/rel.h modified +23 −18
src/pl/plperl/expected/plperl_trigger.out modified +78 −0
src/pl/plperl/plperl.c modified +2 −0
src/pl/plperl/sql/plperl_trigger.sql modified +14 −0
src/pl/plpgsql/src/pl_exec.c modified +3 −1
src/pl/plpython/expected/plpython_trigger.out modified +74 −4
src/pl/plpython/plpython.c modified +2 −0
src/pl/plpython/sql/plpython_trigger.sql modified +17 −0
src/pl/tcl/expected/pltcl_queries_1.out modified +36 −0
src/pl/tcl/expected/pltcl_queries.out modified +36 −0
src/pl/tcl/expected/pltcl_setup.out modified +4 −0
src/pl/tcl/pltcl.c modified +2 −0
src/pl/tcl/sql/pltcl_queries.sql modified +5 −1
src/pl/tcl/sql/pltcl_setup.sql modified +5 −0
src/test/regress/expected/triggers.out modified +625 −0
src/test/regress/sql/triggers.sql modified +357 −0