From d2a907c6ad28413bf85660ea590e0e21e0d7016c Mon Sep 17 00:00:00 2001 From: "Thomas G. Lockhart" Date: Wed, 16 Sep 1998 14:43:12 +0000 Subject: Markup and editing adjustments... --- doc/src/sgml/ref/create_rule.sgml | 164 +++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 84 deletions(-) (limited to 'doc/src/sgml/ref/create_rule.sgml') diff --git a/doc/src/sgml/ref/create_rule.sgml b/doc/src/sgml/ref/create_rule.sgml index 887632061e..67215937c2 100644 --- a/doc/src/sgml/ref/create_rule.sgml +++ b/doc/src/sgml/ref/create_rule.sgml @@ -14,35 +14,28 @@ - 1998-04-15 + 1998-09-11 - CREATE RULE name - AS ON event - TO object [WHERE condition] - DO [INSTEAD] - [action | NOTHING ] +CREATE RULE name + AS ON event + TO object [ WHERE condition ] + DO [ INSTEAD ] [ action | NOTHING ] - 1998-04-15 + 1998-09-11 Inputs - - - - - - - name +name @@ -52,31 +45,34 @@ - event +event - Event is one of select, update, delete or insert. + Event is one of select, + update, delete + or insert. - object +object - Object is either table or table.column. + Object is either table + or table.column. - condition +condition - Any SQL where clause. new or + Any SQL WHERE clause. new or current can appear instead of an instance variable whenever an instance variable is permissible in SQL. @@ -84,25 +80,23 @@ - action +action - Any SQL-statement. new or + Any SQL statement. new or current can appear instead of an instance variable whenever an instance variable is permissible in SQL. - - - + - 1998-04-15 + 1998-09-11 Outputs @@ -112,6 +106,7 @@ <VARIABLELIST> <VARLISTENTRY> <TERM> +<replaceable>status</replaceable> </TERM> <LISTITEM> <PARA> @@ -136,7 +131,7 @@ <REFSECT1 ID="R1-SQL-CREATERULE-1"> <REFSECT1INFO> - <DATE>1998-04-15</DATE> + <DATE>1998-09-11</DATE> </REFSECT1INFO> <TITLE> Description @@ -146,13 +141,13 @@ accessed, updated, inserted or deleted, there is a current instance (for retrieves, updates and deletes) and a new instance (for updates and appends). If the <replaceable class="parameter">event</replaceable> - specified in the <literal>on</literal> clause and the + specified in the ON clause and the <replaceable class="parameter">condition</replaceable> specified in the - <literal>where</literal> clause are true for the current instance, the + WHERE clause are true for the current instance, the <replaceable class="parameter">action</replaceable> part of the rule is executed. First, however, values from fields in the current instance and/or the new instance are substituted for - <literal> current.</literal><replaceable class="parameter">attribute-name</replaceable> + <literal>current.</literal><replaceable class="parameter">attribute-name</replaceable> and <literal>new.</literal><replaceable class="parameter">attribute-name</replaceable>. </para> <para> @@ -163,13 +158,13 @@ <REFSECT2 ID="R2-SQL-CREATERULE-3"> <REFSECT2INFO> - <DATE>1998-04-15</DATE> + <DATE>1998-09-11</DATE> </REFSECT2INFO> <TITLE> Notes - A note of caution about SQL rules is in order. If the same class name + A caution about SQL rules is in order. If the same class name or instance variable appears in the event, the condition and the @@ -179,13 +174,14 @@ variables that are shared between these clauses. For example, the following two rules have the same semantics: - on update to EMP.salary where EMP.name = "Joe" - do update EMP ( ... ) where ... +on update to EMP.salary where EMP.name = "Joe" + do update EMP ( ... ) where ... - on update to EMP-1.salary where EMP-2.name = "Joe" - do update EMP-3 ( ... ) where ... +on update to EMP-1.salary where EMP-2.name = "Joe" + do update EMP-3 ( ... ) where ... - Each rule can have the optional tag instead. Without + Each rule can have the optional tag INSTEAD. +Without this tag, action will be performed in addition to the user command when the event in the @@ -194,7 +190,7 @@ action part will be done instead of the user command. In this later case, the action can be the keyword - nothing. + NOTHING. When choosing between the rewrite and instance rule systems for a @@ -205,32 +201,33 @@ It is very important to note that the rewrite rule system will neither detect nor process circular rules. For example, though each - of the following two rule definitions are accepted by Postgres, the - retrieve command will cause Postgres to crash: + of the following two rule definitions are accepted by + Postgres, the + retrieve command will cause Postgres to crash: Example of a circular rewrite rule combination. - create rule bad_rule_combination_1 is - on select to EMP - do instead select to TOYEMP +create rule bad_rule_combination_1 is + on select to EMP + do instead select to TOYEMP - create rule bad_rule_combination_2 is - on select to TOYEMP - do instead select to EMP +create rule bad_rule_combination_2 is + on select to TOYEMP + do instead select to EMP - This attempt to retrieve from EMP will cause Postgres to crash. + This attempt to retrieve from EMP will cause + Postgres to crash. - select * from EMP +select * from EMP You must have rule definition access to a class in order - to define a rule on it (see change acl(l)). - - There is no manpage change or change_acl. What is intended? - + to define a rule on it. Use GRANT +and REVOKE to change permissions. + @@ -240,13 +237,13 @@ Usage - Make Sam get the same salary adjustment as Joe + Make Sam get the same salary adjustment as Joe: - create rule example_1 is - on update EMP.salary where current.name = "Joe" - do update EMP (salary = new.salary) - where EMP.name = "Sam" +create rule example_1 is + on update EMP.salary where current.name = "Joe" + do update EMP (salary = new.salary) + where EMP.name = "Sam" At the time Joe receives a salary adjustment, the event @@ -257,44 +254,45 @@ Joe's salary on to Sam. - Make Bill get Joe's salary when it is accessed + Make Bill get Joe's salary when it is accessed: - create rule example_2 is - - on select to EMP.salary - where current.name = "Bill" - do instead - select (EMP.salary) from EMP where EMP.name = "Joe" +create rule example_2 is + on select to EMP.salary + where current.name = "Bill" + do instead + select (EMP.salary) from EMP + where EMP.name = "Joe" Deny Joe access to the salary of employees in the shoe - department. (pg_username() returns the name of - the current user) + department (current_user returns the name of + the current user): - create rule example_3 is - on select to EMP.salary - where current.dept = "shoe" and pg_username() = "Joe" - do instead nothing +create rule example_3 is + on select to EMP.salary + where current.dept = "shoe" and current_user = "Joe" + do instead nothing Create a view of the employees working in the toy department. - create TOYEMP(name = char16, salary = int4) +create TOYEMP(name = char16, salary = int4) - create rule example_4 is - on select to TOYEMP - do instead select (EMP.name, EMP.salary) from EMP - where EMP.dept = "toy" +create rule example_4 is + on select to TOYEMP + do instead + select (EMP.name, EMP.salary) from EMP + where EMP.dept = "toy" All new employees must make 5,000 or less - create rule example_5 is - on insert to EMP where new.salary > 5000 - do update newset salary = 5000 +create rule example_5 is + on insert to EMP where new.salary > 5000 + do update newset salary = 5000 @@ -303,9 +301,6 @@ Bugs - - instead rules do not work properly. - The object in a SQL rule cannot be an array reference and cannot have parameters. @@ -328,18 +323,19 @@ Compatibility - CREATE RULE statement is a PostgreSQL language extension. + CREATE RULE statement is a Postgres + language extension. - 1998-04-15 + 1998-09-11 SQL92 - There is no CREATE RULE statement in SQL92. + There is no CREATE RULE statement in SQL92. -- cgit v1.2.1