From 4a3bf197eb3ca020bc0eb0d5bc5d3838fd1e6851 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 6 Nov 2001 23:54:32 +0000 Subject: [PATCH] Add some notes about conditional rules used with views. --- doc/src/sgml/ref/create_rule.sgml | 46 +++++++++++++++++++++++++++---- doc/src/sgml/ref/create_view.sgml | 10 +++++-- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/doc/src/sgml/ref/create_rule.sgml b/doc/src/sgml/ref/create_rule.sgml index 3d7e53ea52..ee17fbdded 100644 --- a/doc/src/sgml/ref/create_rule.sgml +++ b/doc/src/sgml/ref/create_rule.sgml @@ -1,5 +1,5 @@ @@ -196,10 +196,10 @@ CREATE - 2001-01-05 + 2001-11-06 - Notes + Rules and Views Presently, ON SELECT rules must be unconditional INSTEAD rules and must @@ -207,10 +207,44 @@ CREATE rule effectively turns the object table into a view, whose visible contents are the rows returned by the rule's SELECT query rather than whatever had been stored in the table (if anything). It is considered - better style to write a CREATE VIEW command than to create a table and - define an ON SELECT rule for it. + better style to write a CREATE VIEW command than to create a real table + and define an ON SELECT rule for it. + + + + creates a dummy table (with no underlying + storage) and associates an ON SELECT rule with it. The system will not + allow updates to the view, since it knows there is no real table there. + You can create the + illusion of an updatable view by defining ON INSERT, ON UPDATE, and + ON DELETE rules (or any subset of those that's sufficient + for your purposes) to replace update actions on the view with + appropriate updates on other tables. + + There is a catch if you try to use conditional + rules for view updates: there must be an unconditional + INSTEAD rule for each action you wish to allow on the view. If the + rule is conditional, or is not INSTEAD, then the system will still reject + attempts to perform the update action, because it thinks it might end up + trying to perform the action on the dummy table in some cases. + If you want to + handle all the useful cases in conditional rules, you can; just add an + unconditional DO INSTEAD NOTHING rule to ensure that the system + understands it will never be called on to update the dummy table. Then + make the conditional rules non-INSTEAD; in the cases where they fire, + they add to the default INSTEAD NOTHING action. + + + + + + 2001-01-05 + + + Notes + You must have rule definition access to a table in order to define a rule on it. Use GRANT @@ -267,7 +301,7 @@ UPDATE mytable SET name = 'foo' WHERE id = 42; Compatibility - + 1998-09-11 diff --git a/doc/src/sgml/ref/create_view.sgml b/doc/src/sgml/ref/create_view.sgml index bb383e41e5..cc533e1824 100644 --- a/doc/src/sgml/ref/create_view.sgml +++ b/doc/src/sgml/ref/create_view.sgml @@ -1,5 +1,5 @@ @@ -102,7 +102,7 @@ ERROR: Relation 'view' already exi -NOTICE create: attribute named "column" has an unknown type +NOTICE: Attribute 'column' has an unknown type @@ -149,7 +149,11 @@ CREATE VIEW vista AS SELECT text 'Hello World' - Currently, views are read only. + Currently, views are read only: the system will not allow an insert, + update, or delete on a view. You can get the effect of an updatable + view by creating rules that rewrite inserts, etc. on the view into + appropriate actions on other tables. For more information see + . -- 2.40.0