@@ -192,12 +192,14 @@ CREATE VIEW [ <replaceable>schema</replaceable> . ] <replaceable>view_name</repl
192
192
<listitem>
193
193
<para>
194
194
This option controls the behavior of automatically updatable views. When
195
- this option is specified, <command>INSERT</command> and <command>UPDATE</command>
195
+ this option is specified, <command>INSERT</command>,
196
+ <command>UPDATE</command>, and <command>MERGE</command>
196
197
commands on the view will be checked to ensure that new rows satisfy the
197
198
view-defining condition (that is, the new rows are checked to ensure that
198
199
they are visible through the view). If they are not, the update will be
199
200
rejected. If the <literal>CHECK OPTION</literal> is not specified,
200
- <command>INSERT</command> and <command>UPDATE</command> commands on the view are
201
+ <command>INSERT</command>, <command>UPDATE</command>, and
202
+ <command>MERGE</command> commands on the view are
201
203
allowed to create rows that are not visible through the view. The
202
204
following check options are supported:
203
205
@@ -247,7 +249,8 @@ CREATE VIEW [ <replaceable>schema</replaceable> . ] <replaceable>view_name</repl
247
249
<command>INSERT</command> or <command>UPDATE</command> command to be rewritten, then
248
250
all check options will be ignored in the rewritten query, including any
249
251
checks from automatically updatable views defined on top of the relation
250
- with the <literal>INSTEAD</literal> rule.
252
+ with the <literal>INSTEAD</literal> rule. <command>MERGE</command> is not
253
+ supported if the view or any of its base relations have rules.
251
254
</para>
252
255
</listitem>
253
256
</varlistentry>
@@ -360,7 +363,8 @@ CREATE VIEW vista AS SELECT text 'Hello World' AS hello;
360
363
361
364
<para>
362
365
Simple views are automatically updatable: the system will allow
363
- <command>INSERT</command>, <command>UPDATE</command> and <command>DELETE</command> statements
366
+ <command>INSERT</command>, <command>UPDATE</command>,
367
+ <command>DELETE</command>, and <command>MERGE</command> statements
364
368
to be used on the view in the same way as on a regular table. A view is
365
369
automatically updatable if it satisfies all of the following conditions:
366
370
@@ -400,13 +404,15 @@ CREATE VIEW vista AS SELECT text 'Hello World' AS hello;
400
404
An automatically updatable view may contain a mix of updatable and
401
405
non-updatable columns. A column is updatable if it is a simple reference
402
406
to an updatable column of the underlying base relation; otherwise the
403
- column is read-only, and an error will be raised if an <command>INSERT</command>
404
- or <command>UPDATE</command> statement attempts to assign a value to it.
407
+ column is read-only, and an error will be raised if an
408
+ <command>INSERT</command>, <command>UPDATE</command>, or
409
+ <command>MERGE</command> statement attempts to assign a value to it.
405
410
</para>
406
411
407
412
<para>
408
413
If the view is automatically updatable the system will convert any
409
- <command>INSERT</command>, <command>UPDATE</command> or <command>DELETE</command> statement
414
+ <command>INSERT</command>, <command>UPDATE</command>,
415
+ <command>DELETE</command>, or <command>MERGE</command> statement
410
416
on the view into the corresponding statement on the underlying base
411
417
relation. <command>INSERT</command> statements that have an <literal>ON
412
418
CONFLICT UPDATE</literal> clause are fully supported.
@@ -415,17 +421,21 @@ CREATE VIEW vista AS SELECT text 'Hello World' AS hello;
415
421
<para>
416
422
If an automatically updatable view contains a <literal>WHERE</literal>
417
423
condition, the condition restricts which rows of the base relation are
418
- available to be modified by <command>UPDATE</command> and <command>DELETE</command>
419
- statements on the view. However, an <command>UPDATE</command> is allowed to
424
+ available to be modified by <command>UPDATE</command>,
425
+ <command>DELETE</command>, and <command>MERGE</command>
426
+ statements on the view. However, an <command>UPDATE</command> or
427
+ <command>MERGE</command> is allowed to
420
428
change a row so that it no longer satisfies the <literal>WHERE</literal>
421
429
condition, and thus is no longer visible through the view. Similarly,
422
- an <command>INSERT</command> command can potentially insert base-relation rows
430
+ an <command>INSERT</command> or <command>MERGE</command> command can
431
+ potentially insert base-relation rows
423
432
that do not satisfy the <literal>WHERE</literal> condition and thus are not
424
433
visible through the view (<literal>ON CONFLICT UPDATE</literal> may
425
434
similarly affect an existing row not visible through the view).
426
435
The <literal>CHECK OPTION</literal> may be used to prevent
427
- <command>INSERT</command> and <command>UPDATE</command> commands from creating
428
- such rows that are not visible through the view.
436
+ <command>INSERT</command>, <command>UPDATE</command>, and
437
+ <command>MERGE</command> commands from creating such rows that are not
438
+ visible through the view.
429
439
</para>
430
440
431
441
<para>
@@ -443,14 +453,16 @@ CREATE VIEW vista AS SELECT text 'Hello World' AS hello;
443
453
444
454
<para>
445
455
A more complex view that does not satisfy all these conditions is
446
- read-only by default: the system will not allow an insert, update, or
447
- delete on the view. You can get the effect of an updatable view by
456
+ read-only by default: the system will not allow an <command>INSERT</command>,
457
+ <command>UPDATE</command>, <command>DELETE</command>, or <command>MERGE</command>
458
+ on the view. You can get the effect of an updatable view by
448
459
creating <literal>INSTEAD OF</literal> triggers on the view, which must
449
460
convert attempted inserts, etc. on the view into appropriate actions
450
461
on other tables. For more information see <xref
451
462
linkend="sql-createtrigger"/>. Another possibility is to create rules
452
463
(see <xref linkend="sql-createrule"/>), but in practice triggers are
453
- easier to understand and use correctly.
464
+ easier to understand and use correctly. Also note that <command>MERGE</command>
465
+ is not supported on relations with rules.
454
466
</para>
455
467
456
468
<para>
0 commit comments