Skip to content

Commit 3f9fe9b

Browse files
committed
Doc: update CREATE RULE ref page's hoary discussion of views.
This text left one with the impression that an ON SELECT rule could be attached to a plain table, which has not been true since commit 264c068 (meaning the text was already misleading when written, evidently by me in 96bd67f). However, it didn't get really bad until b23cd18 removed the convert-a-table-to-a-view logic, which had made it possible for scripts that thought they were attaching ON SELECTs to tables to still work. Rewrite into a form that makes it clear that an ON SELECT rule is better regarded as an implementation detail of a view. Pre-v16, point out that adding ON SELECT to a table actually converts it to a view. Per bug #18178 from Joshua Uyehara. Back-patch to all supported branches. Discussion: https://postgr.es/m/18178-05534d7064044d2d@postgresql.org
1 parent 272db03 commit 3f9fe9b

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

doc/src/sgml/ref/create_rule.sgml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,17 @@ CREATE [ OR REPLACE ] RULE <replaceable class="parameter">name</replaceable> AS
5959
</para>
6060

6161
<para>
62-
Presently, <literal>ON SELECT</literal> rules must be unconditional
63-
<literal>INSTEAD</literal> rules and must have actions that consist
64-
of a single <command>SELECT</command> command. Thus, an
65-
<literal>ON SELECT</literal> rule effectively turns the table into
66-
a view, whose visible contents are the rows returned by the rule's
67-
<command>SELECT</command> command rather than whatever had been
68-
stored in the table (if anything). It is considered better style
69-
to write a <command>CREATE VIEW</command> command than to create a
70-
real table and define an <literal>ON SELECT</literal> rule for it.
62+
Presently, <literal>ON SELECT</literal> rules can only be attached
63+
to views. (Attaching one to a table converts the table into a view.)
64+
Such a rule must be named <literal>"_RETURN"</literal>,
65+
must be an unconditional <literal>INSTEAD</literal> rule, and must have
66+
an action that consists of a single <command>SELECT</command> command.
67+
This command defines the visible contents of the view. (The view
68+
itself is basically a dummy table with no storage.) It's best to
69+
regard such a rule as an implementation detail. While a view can be
70+
redefined via <literal>CREATE OR REPLACE RULE "_RETURN" AS
71+
...</literal>, it's better style to use <literal>CREATE OR REPLACE
72+
VIEW</literal>.
7173
</para>
7274

7375
<para>

0 commit comments

Comments
 (0)