Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4a3bf19

Browse files
committed
Add some notes about conditional rules used with views.
1 parentf688c1e commit4a3bf19

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

‎doc/src/sgml/ref/create_rule.sgml

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_rule.sgml,v 1.28 2001/10/09 18:46:00 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_rule.sgml,v 1.29 2001/11/06 23:54:32 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -196,21 +196,55 @@ CREATE
196196

197197
<refsect2 id="R2-SQL-CREATERULE-3">
198198
<refsect2info>
199-
<date>2001-01-05</date>
199+
<date>2001-11-06</date>
200200
</refsect2info>
201201
<title>
202-
Notes
202+
Rules and Views
203203
</title>
204204
<para>
205205
Presently, ON SELECT rules must be unconditional INSTEAD rules and must
206206
have actions that consist of a single SELECT query. Thus, an ON SELECT
207207
rule effectively turns the object table into a view, whose visible
208208
contents are the rows returned by the rule's SELECT query rather than
209209
whatever had been stored in the table (if anything). It is considered
210-
better style to write a CREATE VIEW command than to create a table and
211-
define an ON SELECT rule for it.
210+
better style to write a CREATE VIEW command than to create a real table
211+
and define an ON SELECT rule for it.
212+
</para>
213+
214+
<para>
215+
<xref linkend="sql-createview"> creates a dummy table (with no underlying
216+
storage) and associates an ON SELECT rule with it. The system will not
217+
allow updates to the view, since it knows there is no real table there.
218+
You can create the
219+
illusion of an updatable view by defining ON INSERT, ON UPDATE, and
220+
ON DELETE rules (or any subset of those that's sufficient
221+
for your purposes) to replace update actions on the view with
222+
appropriate updates on other tables.
212223
</para>
213224

225+
<para>
226+
There is a catch if you try to use conditional
227+
rules for view updates: there <emphasis>must</> be an unconditional
228+
INSTEAD rule for each action you wish to allow on the view. If the
229+
rule is conditional, or is not INSTEAD, then the system will still reject
230+
attempts to perform the update action, because it thinks it might end up
231+
trying to perform the action on the dummy table in some cases.
232+
If you want to
233+
handle all the useful cases in conditional rules, you can; just add an
234+
unconditional DO INSTEAD NOTHING rule to ensure that the system
235+
understands it will never be called on to update the dummy table. Then
236+
make the conditional rules non-INSTEAD; in the cases where they fire,
237+
they add to the default INSTEAD NOTHING action.
238+
</para>
239+
</refsect2>
240+
241+
<refsect2 id="R2-SQL-CREATERULE-4">
242+
<refsect2info>
243+
<date>2001-01-05</date>
244+
</refsect2info>
245+
<title>
246+
Notes
247+
</title>
214248
<para>
215249
You must have rule definition access to a table in order
216250
to define a rule on it. Use <command>GRANT</command>
@@ -267,7 +301,7 @@ UPDATE mytable SET name = 'foo' WHERE id = 42;
267301
Compatibility
268302
</title>
269303

270-
<refsect2 id="R2-SQL-CREATERULE-4">
304+
<refsect2 id="R2-SQL-CREATERULE-5">
271305
<refsect2info>
272306
<date>1998-09-11</date>
273307
</refsect2info>

‎doc/src/sgml/ref/create_view.sgml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_view.sgml,v 1.12 2001/09/03 12:57:49 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_view.sgml,v 1.13 2001/11/06 23:54:32 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -102,7 +102,7 @@ ERROR: Relation '<replaceable class="parameter">view</replaceable>' already exi
102102
</varlistentry>
103103
<varlistentry>
104104
<term><computeroutput>
105-
NOTICE create: attribute named "<replaceable class="parameter">column</replaceable>" has an unknown type
105+
NOTICE: Attribute '<replaceable class="parameter">column</replaceable>' has an unknown type
106106
</computeroutput></term>
107107
<listitem>
108108
<para>
@@ -149,7 +149,11 @@ CREATE VIEW vista AS SELECT text 'Hello World'
149149
</title>
150150

151151
<para>
152-
Currently, views are read only.
152+
Currently, views are read only: the system will not allow an insert,
153+
update, or delete on a view. You can get the effect of an updatable
154+
view by creating rules that rewrite inserts, etc. on the view into
155+
appropriate actions on other tables. For more information see
156+
<xref linkend="sql-createrule">.
153157
</para>
154158

155159
<para>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp