1- <!-- $PostgreSQL: pgsql/doc/src/sgml/rules.sgml,v 1.52 2008/12/16 03:12:08 momjian Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/rules.sgml,v 1.53 2009/11/05 23:24:22 tgl Exp $ -->
22
33<chapter id="rules">
44<title>The Rule System</title>
@@ -435,8 +435,7 @@ CREATE VIEW shoe_ready AS
435435 <note>
436436 <para>
437437 The two extra range
438- table entries for <literal>NEW</> and <literal>OLD</> (named <literal>*NEW*</> and <literal>*OLD*</> for
439- historical reasons in the printed query tree) you can see in
438+ table entries for <literal>NEW</> and <literal>OLD</> that you can see in
440439 the <structname>pg_rewrite</structname> entry aren't of interest
441440 for <command>SELECT</command> rules.
442441 </para>
@@ -504,7 +503,7 @@ SELECT shoelace.sl_name, shoelace.sl_avail,
504503SELECT s.sl_name, s.sl_avail,
505504 s.sl_color, s.sl_len, s.sl_unit,
506505 s.sl_len * u.un_fact AS sl_len_cm
507- FROM shoelace*OLD* , shoelace*NEW* ,
506+ FROM shoelaceold , shoelacenew ,
508507 shoelace_data s, unit u
509508 WHERE s.sl_unit = u.un_name;
510509</programlisting>
@@ -531,7 +530,7 @@ SELECT shoelace.sl_name, shoelace.sl_avail,
531530</programlisting>
532531
533532 There is one difference however: the subquery's range table has two
534- extra entries <literal>shoelace*OLD* </> and <literal>shoelace*NEW* </>. These entries don't
533+ extra entries <literal>shoelaceold </> and <literal>shoelacenew </>. These entries don't
535534 participate directly in the query, since they aren't referenced by
536535 the subquery's join tree or target list. The rewriter uses them
537536 to store the access privilege check information that was originally present
@@ -546,7 +545,7 @@ SELECT shoelace.sl_name, shoelace.sl_avail,
546545 the remaining range-table entries in the top query (in this example there
547546 are no more), and it will recursively check the range-table entries in
548547 the added subquery to see if any of them reference views. (But it
549- won't expand <literal>*OLD* </> or <literal>*NEW* </> — otherwise we'd have infinite recursion!)
548+ won't expand <literal>old </> or <literal>new </> — otherwise we'd have infinite recursion!)
550549 In this example, there are no rewrite rules for <literal>shoelace_data</> or <literal>unit</>,
551550 so rewriting is complete and the above is the final result given to
552551 the planner.
@@ -1073,15 +1072,15 @@ NEW.sl_avail <> OLD.sl_avail
10731072
10741073<programlisting>
10751074INSERT INTO shoelace_log VALUES (
1076- *NEW* .sl_name,*NEW* .sl_avail,
1075+ new .sl_name,new .sl_avail,
10771076 current_user, current_timestamp )
1078- FROM shoelace_data*NEW* , shoelace_data*OLD* ;
1077+ FROM shoelace_datanew , shoelace_dataold ;
10791078</programlisting>
10801079
10811080 (This looks a little strange since you cannot normally write
10821081 <literal>INSERT ... VALUES ... FROM</>. The <literal>FROM</>
10831082 clause here is just to indicate that there are range-table entries
1084- in the query tree for <literal>*NEW* </> and <literal>*OLD* </>.
1083+ in the query tree for <literal>new </> and <literal>old </>.
10851084 These are needed so that they can be referenced by variables in
10861085 the <command>INSERT</command> command's query tree.)
10871086</para>
@@ -1094,9 +1093,9 @@ INSERT INTO shoelace_log VALUES (
10941093
10951094<programlisting>
10961095INSERT INTO shoelace_log VALUES (
1097- *NEW* .sl_name,*NEW* .sl_avail,
1096+ new .sl_name,new .sl_avail,
10981097 current_user, current_timestamp )
1099- FROM shoelace_data*NEW* , shoelace_data*OLD* ,
1098+ FROM shoelace_datanew , shoelace_dataold ,
11001099 <emphasis>shoelace_data shoelace_data</emphasis>;
11011100</programlisting>
11021101
@@ -1105,11 +1104,11 @@ INSERT INTO shoelace_log VALUES (
11051104
11061105<programlisting>
11071106INSERT INTO shoelace_log VALUES (
1108- *NEW* .sl_name,*NEW* .sl_avail,
1107+ new .sl_name,new .sl_avail,
11091108 current_user, current_timestamp )
1110- FROM shoelace_data*NEW* , shoelace_data*OLD* ,
1109+ FROM shoelace_datanew , shoelace_dataold ,
11111110 shoelace_data shoelace_data
1112- <emphasis>WHERE*NEW* .sl_avail <>*OLD* .sl_avail</emphasis>;
1111+ <emphasis>WHEREnew .sl_avail <>old .sl_avail</emphasis>;
11131112</programlisting>
11141113
11151114 (This looks even stranger, since <literal>INSERT ... VALUES</> doesn't have
@@ -1125,11 +1124,11 @@ INSERT INTO shoelace_log VALUES (
11251124
11261125<programlisting>
11271126INSERT INTO shoelace_log VALUES (
1128- *NEW* .sl_name,*NEW* .sl_avail,
1127+ new .sl_name,new .sl_avail,
11291128 current_user, current_timestamp )
1130- FROM shoelace_data*NEW* , shoelace_data*OLD* ,
1129+ FROM shoelace_datanew , shoelace_dataold ,
11311130 shoelace_data shoelace_data
1132- WHERE*NEW* .sl_avail <>*OLD* .sl_avail
1131+ WHEREnew .sl_avail <>old .sl_avail
11331132 <emphasis>AND shoelace_data.sl_name = 'sl7'</emphasis>;
11341133</programlisting>
11351134 </para>
@@ -1143,9 +1142,9 @@ INSERT INTO shoelace_log VALUES (
11431142INSERT INTO shoelace_log VALUES (
11441143 <emphasis>shoelace_data.sl_name</emphasis>, <emphasis>6</emphasis>,
11451144 current_user, current_timestamp )
1146- FROM shoelace_data*NEW* , shoelace_data*OLD* ,
1145+ FROM shoelace_datanew , shoelace_dataold ,
11471146 shoelace_data shoelace_data
1148- WHERE <emphasis>6</emphasis> <>*OLD* .sl_avail
1147+ WHERE <emphasis>6</emphasis> <>old .sl_avail
11491148 AND shoelace_data.sl_name = 'sl7';
11501149</programlisting>
11511150
@@ -1158,7 +1157,7 @@ INSERT INTO shoelace_log VALUES (
11581157INSERT INTO shoelace_log VALUES (
11591158 shoelace_data.sl_name, 6,
11601159 current_user, current_timestamp )
1161- FROM shoelace_data*NEW* , shoelace_data*OLD* ,
1160+ FROM shoelace_datanew , shoelace_dataold ,
11621161 shoelace_data shoelace_data
11631162 WHERE 6 <> <emphasis>shoelace_data.sl_avail</emphasis>
11641163 AND shoelace_data.sl_name = 'sl7';
@@ -1455,7 +1454,7 @@ SELECT shoelace_arrive.arr_name, shoelace_arrive.arr_quant
14551454UPDATE shoelace
14561455 SET sl_avail = shoelace.sl_avail + shoelace_arrive.arr_quant
14571456 FROM shoelace_arrive shoelace_arrive, shoelace_ok shoelace_ok,
1458- shoelace_ok*OLD* , shoelace_ok*NEW* ,
1457+ shoelace_okold , shoelace_oknew ,
14591458 shoelace shoelace
14601459 WHERE shoelace.sl_name = shoelace_arrive.arr_name;
14611460</programlisting>
@@ -1473,9 +1472,9 @@ UPDATE shoelace_data
14731472 sl_len = shoelace.sl_len,
14741473 sl_unit = shoelace.sl_unit
14751474 FROM shoelace_arrive shoelace_arrive, shoelace_ok shoelace_ok,
1476- shoelace_ok*OLD* , shoelace_ok*NEW* ,
1477- shoelace shoelace, shoelace*OLD* ,
1478- shoelace*NEW* , shoelace_data shoelace_data
1475+ shoelace_okold , shoelace_oknew ,
1476+ shoelace shoelace, shoelaceold ,
1477+ shoelacenew , shoelace_data shoelace_data
14791478 WHERE shoelace.sl_name = shoelace_arrive.arr_name
14801479 AND shoelace_data.sl_name = shoelace.sl_name;
14811480</programlisting>
@@ -1493,10 +1492,10 @@ UPDATE shoelace_data
14931492 sl_len = s.sl_len,
14941493 sl_unit = s.sl_unit
14951494 FROM shoelace_arrive shoelace_arrive, shoelace_ok shoelace_ok,
1496- shoelace_ok*OLD* , shoelace_ok*NEW* ,
1497- shoelace shoelace, shoelace*OLD* ,
1498- shoelace*NEW* , shoelace_data shoelace_data,
1499- shoelace*OLD* , shoelace*NEW* ,
1495+ shoelace_okold , shoelace_oknew ,
1496+ shoelace shoelace, shoelaceold ,
1497+ shoelacenew , shoelace_data shoelace_data,
1498+ shoelaceold , shoelacenew ,
15001499 shoelace_data s, unit u
15011500 WHERE s.sl_name = shoelace_arrive.arr_name
15021501 AND shoelace_data.sl_name = s.sl_name;
@@ -1512,12 +1511,12 @@ SELECT s.sl_name,
15121511 current_user,
15131512 current_timestamp
15141513 FROM shoelace_arrive shoelace_arrive, shoelace_ok shoelace_ok,
1515- shoelace_ok*OLD* , shoelace_ok*NEW* ,
1516- shoelace shoelace, shoelace*OLD* ,
1517- shoelace*NEW* , shoelace_data shoelace_data,
1518- shoelace*OLD* , shoelace*NEW* ,
1514+ shoelace_okold , shoelace_oknew ,
1515+ shoelace shoelace, shoelaceold ,
1516+ shoelacenew , shoelace_data shoelace_data,
1517+ shoelaceold , shoelacenew ,
15191518 shoelace_data s, unit u,
1520- shoelace_data*OLD* , shoelace_data*NEW*
1519+ shoelace_dataold , shoelace_datanew
15211520 shoelace_log shoelace_log
15221521 WHERE s.sl_name = shoelace_arrive.arr_name
15231522 AND shoelace_data.sl_name = s.sl_name