diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-10-10 13:43:33 -0400 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-10-10 13:45:07 -0400 |
| commit | 2ec993a7cbdd8e251817ac6bbc9a704ce8346f73 (patch) | |
| tree | 1568fb4b00b6fa7997755113a3d0bbfead45c1fb /doc/src/sgml/ref/create_rule.sgml | |
| parent | f7b15b5098ee89a2628129fbbef9901bded9d27b (diff) | |
| download | postgresql-2ec993a7cbdd8e251817ac6bbc9a704ce8346f73.tar.gz | |
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.
Diffstat (limited to 'doc/src/sgml/ref/create_rule.sgml')
| -rw-r--r-- | doc/src/sgml/ref/create_rule.sgml | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/doc/src/sgml/ref/create_rule.sgml b/doc/src/sgml/ref/create_rule.sgml index 5d2182c2ca..e7c88497d6 100644 --- a/doc/src/sgml/ref/create_rule.sgml +++ b/doc/src/sgml/ref/create_rule.sgml @@ -53,7 +53,7 @@ CREATE [ OR REPLACE ] RULE <replaceable class="parameter">name</replaceable> AS physical row, you probably want to use a trigger, not a rule. More information about the rules system is in <xref linkend="rules">. </para> - + <para> Presently, <literal>ON SELECT</literal> rules must be unconditional <literal>INSTEAD</literal> rules and must have actions that consist @@ -73,7 +73,9 @@ CREATE [ OR REPLACE ] RULE <replaceable class="parameter">name</replaceable> AS sufficient for your purposes) to replace update actions on the view with appropriate updates on other tables. If you want to support <command>INSERT RETURNING</> and so on, then be sure to put a suitable - <literal>RETURNING</> clause into each of these rules. + <literal>RETURNING</> clause into each of these rules. Alternatively, + an updatable view can be implemented using <literal>INSTEAD OF</> + triggers (see <xref linkend="sql-createtrigger">). </para> <para> @@ -232,12 +234,12 @@ CREATE [ OR REPLACE ] RULE <replaceable class="parameter">name</replaceable> AS <programlisting> CREATE RULE "_RETURN" AS ON SELECT TO t1 - DO INSTEAD + DO INSTEAD SELECT * FROM t2; CREATE RULE "_RETURN" AS ON SELECT TO t2 - DO INSTEAD + DO INSTEAD SELECT * FROM t1; SELECT * FROM t1; |
