@@ -192,12 +192,14 @@ CREATE VIEW [ <replaceable>schema</replaceable> . ] <replaceable>view_name</repl
192192 <listitem>
193193 <para>
194194 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>
196197 commands on the view will be checked to ensure that new rows satisfy the
197198 view-defining condition (that is, the new rows are checked to ensure that
198199 they are visible through the view). If they are not, the update will be
199200 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
201203 allowed to create rows that are not visible through the view. The
202204 following check options are supported:
203205
@@ -247,7 +249,8 @@ CREATE VIEW [ <replaceable>schema</replaceable> . ] <replaceable>view_name</repl
247249 <command>INSERT</command> or <command>UPDATE</command> command to be rewritten, then
248250 all check options will be ignored in the rewritten query, including any
249251 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.
251254 </para>
252255 </listitem>
253256 </varlistentry>
@@ -360,7 +363,8 @@ CREATE VIEW vista AS SELECT text 'Hello World' AS hello;
360363
361364 <para>
362365 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
364368 to be used on the view in the same way as on a regular table. A view is
365369 automatically updatable if it satisfies all of the following conditions:
366370
@@ -400,13 +404,15 @@ CREATE VIEW vista AS SELECT text 'Hello World' AS hello;
400404 An automatically updatable view may contain a mix of updatable and
401405 non-updatable columns. A column is updatable if it is a simple reference
402406 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.
405410 </para>
406411
407412 <para>
408413 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
410416 on the view into the corresponding statement on the underlying base
411417 relation. <command>INSERT</command> statements that have an <literal>ON
412418 CONFLICT UPDATE</literal> clause are fully supported.
@@ -415,17 +421,21 @@ CREATE VIEW vista AS SELECT text 'Hello World' AS hello;
415421 <para>
416422 If an automatically updatable view contains a <literal>WHERE</literal>
417423 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
420428 change a row so that it no longer satisfies the <literal>WHERE</literal>
421429 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
423432 that do not satisfy the <literal>WHERE</literal> condition and thus are not
424433 visible through the view (<literal>ON CONFLICT UPDATE</literal> may
425434 similarly affect an existing row not visible through the view).
426435 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.
429439 </para>
430440
431441 <para>
@@ -443,14 +453,16 @@ CREATE VIEW vista AS SELECT text 'Hello World' AS hello;
443453
444454 <para>
445455 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
448459 creating <literal>INSTEAD OF</literal> triggers on the view, which must
449460 convert attempted inserts, etc. on the view into appropriate actions
450461 on other tables. For more information see <xref
451462 linkend="sql-createtrigger"/>. Another possibility is to create rules
452463 (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.
454466 </para>
455467
456468 <para>
0 commit comments