Commit edf68b2e authored by Andres Freund's avatar Andres Freund

Improve ON CONFLICT documentation.

Author: Peter Geoghegan and Andres Freund
Discussion: CAM3SWZScpWzQ-7EJC77vwqzZ1GO8GNmURQ1QqDQ3wRn7AbW1Cg@mail.gmail.com
Backpatch: 9.5, where ON CONFLICT was introduced
parent 32f15d05
...@@ -99,7 +99,8 @@ INSERT INTO <replaceable class="PARAMETER">table_name</replaceable> [ AS <replac ...@@ -99,7 +99,8 @@ INSERT INTO <replaceable class="PARAMETER">table_name</replaceable> [ AS <replac
<para> <para>
You must have <literal>INSERT</literal> privilege on a table in You must have <literal>INSERT</literal> privilege on a table in
order to insert into it. If <literal>ON CONFLICT DO UPDATE</> is order to insert into it. If <literal>ON CONFLICT DO UPDATE</> is
present the <literal>UPDATE</literal> privilege is also required. present, <literal>UPDATE</literal> privilege on the table is also
required.
</para> </para>
<para> <para>
...@@ -126,366 +127,378 @@ INSERT INTO <replaceable class="PARAMETER">table_name</replaceable> [ AS <replac ...@@ -126,366 +127,378 @@ INSERT INTO <replaceable class="PARAMETER">table_name</replaceable> [ AS <replac
<refsect1> <refsect1>
<title>Parameters</title> <title>Parameters</title>
<variablelist> <refsect2 id="SQL-INSERTING-PARAMS">
<varlistentry> <title id="sql-inserting-params-title">Inserting</title>
<term><replaceable class="parameter">with_query</replaceable></term>
<listitem> <para>
<para> This section covers parameters that may be used when only
The <literal>WITH</literal> clause allows you to specify one or more inserting new rows. Parameters <emphasis>exclusively</emphasis>
subqueries that can be referenced by name in the <command>INSERT</> used with the <literal>ON CONFLICT</literal> clause are described
query. See <xref linkend="queries-with"> and <xref linkend="sql-select"> separately.
for details. </para>
</para>
<para> <variablelist>
It is possible for the <replaceable class="parameter">query</replaceable> <varlistentry>
(<command>SELECT</command> statement) <term><replaceable class="parameter">with_query</replaceable></term>
to also contain a <literal>WITH</literal> clause. In such a case both <listitem>
sets of <replaceable>with_query</replaceable> can be referenced within <para>
the <replaceable class="parameter">query</replaceable>, but the The <literal>WITH</literal> clause allows you to specify one or more
second one takes precedence since it is more closely nested. subqueries that can be referenced by name in the <command>INSERT</>
</para> query. See <xref linkend="queries-with"> and <xref linkend="sql-select">
</listitem> for details.
</varlistentry> </para>
<para>
<varlistentry> It is possible for the <replaceable class="parameter">query</replaceable>
<term><replaceable class="PARAMETER">table_name</replaceable></term> (<command>SELECT</command> statement)
<listitem> to also contain a <literal>WITH</literal> clause. In such a case both
<para> sets of <replaceable>with_query</replaceable> can be referenced within
The name (optionally schema-qualified) of an existing table. the <replaceable class="parameter">query</replaceable>, but the
</para> second one takes precedence since it is more closely nested.
</listitem> </para>
</varlistentry> </listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">alias</replaceable></term> <varlistentry>
<listitem> <term><replaceable class="PARAMETER">table_name</replaceable></term>
<para> <listitem>
A substitute name for the target table. When an alias is provided, it <para>
completely hides the actual name of the table. This is particularly The name (optionally schema-qualified) of an existing table.
useful when using <literal>ON CONFLICT DO UPDATE</literal> into a table </para>
named <literal>excluded</literal> as that's also the name of the </listitem>
pseudo-relation containing the proposed row. </varlistentry>
</para>
</listitem> <varlistentry>
</varlistentry> <term><replaceable class="parameter">alias</replaceable></term>
<listitem>
<para>
<varlistentry> A substitute name for <replaceable
<term><replaceable class="PARAMETER">column_name</replaceable></term> class="PARAMETER">table_name</replaceable>. When an alias is
<listitem> provided, it completely hides the actual name of the table.
<para> This is particularly useful when <literal>ON CONFLICT DO
The name of a column in the table named by <replaceable class="PARAMETER">table_name</replaceable>. UPDATE</literal> targets a table named excluded, since that's
The column name can be qualified with a subfield name or array also the name of the special table representing rows proposed
subscript, if needed. (Inserting into only some fields of a for insertion.
composite column leaves the other fields null.) When </para>
referencing a column with <literal>ON CONFLICT DO UPDATE</>, do </listitem>
not include the table's name in the specification of a target </varlistentry>
column. For example, <literal>INSERT ... ON CONFLICT DO UPDATE
tab SET table_name.col = 1</> is invalid (this follows the general
behavior for <command>UPDATE</>). <varlistentry>
</para> <term><replaceable class="PARAMETER">column_name</replaceable></term>
</listitem> <listitem>
</varlistentry> <para>
The name of a column in the table named by <replaceable
<varlistentry> class="PARAMETER">table_name</replaceable>. The column name
<term><literal>DEFAULT VALUES</literal></term> can be qualified with a subfield name or array subscript, if
<listitem> needed. (Inserting into only some fields of a composite
<para> column leaves the other fields null.) When referencing a
All columns will be filled with their default values. column with <literal>ON CONFLICT DO UPDATE</>, do not include
</para> the table's name in the specification of a target column. For
</listitem> example, <literal>INSERT ... ON CONFLICT DO UPDATE tab SET
</varlistentry> table_name.col = 1</> is invalid (this follows the general
behavior for <command>UPDATE</>).
<varlistentry> </para>
<term><replaceable class="PARAMETER">expression</replaceable></term> </listitem>
<listitem> </varlistentry>
<para>
An expression or value to assign to the corresponding column. <varlistentry>
</para> <term><literal>DEFAULT VALUES</literal></term>
</listitem> <listitem>
</varlistentry> <para>
All columns will be filled with their default values.
<varlistentry> </para>
<term><literal>DEFAULT</literal></term> </listitem>
<listitem> </varlistentry>
<para>
The corresponding column will be filled with <varlistentry>
its default value. <term><replaceable class="PARAMETER">expression</replaceable></term>
</para> <listitem>
</listitem> <para>
</varlistentry> An expression or value to assign to the corresponding column.
</para>
<varlistentry> </listitem>
<term><replaceable class="PARAMETER">query</replaceable></term> </varlistentry>
<listitem>
<para> <varlistentry>
A query (<command>SELECT</command> statement) that supplies the <term><literal>DEFAULT</literal></term>
rows to be inserted. Refer to the <listitem>
<xref linkend="sql-select"> <para>
statement for a description of the syntax. The corresponding column will be filled with
</para> its default value.
</listitem> </para>
</varlistentry> </listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">output_expression</replaceable></term> <varlistentry>
<listitem> <term><replaceable class="PARAMETER">query</replaceable></term>
<para> <listitem>
An expression to be computed and returned by the <command>INSERT</> <para>
command after each row is inserted (not updated). The A query (<command>SELECT</command> statement) that supplies the
expression can use any column names of the table named by rows to be inserted. Refer to the
<replaceable class="PARAMETER">table_name</replaceable>. <xref linkend="sql-select">
Write <literal>*</> to return all columns of the inserted row(s). statement for a description of the syntax.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><literal>conflict_target</literal></term> <term><replaceable class="PARAMETER">output_expression</replaceable></term>
<listitem> <listitem>
<para> <para>
Specify which conflicts <literal>ON CONFLICT</literal> refers to. An expression to be computed and returned by the
</para> <command>INSERT</> command after each row is inserted or
</listitem> updated. The expression can use any column names of the table
</varlistentry> named by <replaceable
class="PARAMETER">table_name</replaceable>. Write
<varlistentry> <literal>*</> to return all columns of the inserted or updated
<term><literal>conflict_action</literal></term> row(s).
<listitem> </para>
<para> </listitem>
<literal>DO NOTHING</literal> or <literal>DO UPDATE </varlistentry>
SET</literal> clause specifying the action to be performed in
case of a conflict. <varlistentry>
</para> <term><replaceable class="PARAMETER">output_name</replaceable></term>
</listitem> <listitem>
</varlistentry> <para>
A name to use for a returned column.
<varlistentry> </para>
<term><replaceable class="PARAMETER">output_name</replaceable></term> </listitem>
<listitem> </varlistentry>
<para> </variablelist>
A name to use for a returned column. </refsect2>
</para>
</listitem> <refsect2 id="sql-on-conflict">
</varlistentry> <title id="sql-on-conflict-title"><literal>ON CONFLICT</literal> Clause</title>
<indexterm zone="SQL-INSERT">
<varlistentry> <primary>UPSERT</primary>
<term><replaceable class="PARAMETER">column_name_index</replaceable></term> </indexterm>
<listitem> <indexterm zone="SQL-INSERT">
<para> <primary>ON CONFLICT</primary>
The name of a <replaceable </indexterm>
class="PARAMETER">table_name</replaceable> column. Part of a <para>
unique index inference clause. Follows <command>CREATE The optional <literal>ON CONFLICT</literal> clause specifies an
INDEX</command> format. <literal>SELECT</> privilege on alternative action to raising a unique violation or exclusion
<replaceable class="PARAMETER">column_name_index</replaceable> constraint violation error. For each individual row proposed for
is required. insertion, either the insertion proceeds, or, if an
</para> <emphasis>arbiter</emphasis> constraint or index specified by
</listitem> <parameter>conflict_target</parameter> is violated, the
</varlistentry> alternative <parameter>conflict_action</parameter> is taken.
<literal>ON CONFLICT DO NOTHING</literal> simply avoids inserting
<varlistentry> a row as its alternative action. <literal>ON CONFLICT DO
<term><replaceable class="PARAMETER">expression_index</replaceable></term> UPDATE</literal> updates the existing row that conflicts with the
<listitem> row proposed for insertion as its alternative action.
<para> </para>
Similar to <replaceable
class="PARAMETER">column_name_index</replaceable>, but used to <para>
infer expressions on <replaceable <parameter>conflict_target</parameter> can perform
class="PARAMETER">table_name</replaceable> columns appearing <emphasis>unique index inference</emphasis>. When performing
within index definitions (not simple columns). Part of unique inference, it consists of one or more <replaceable
index inference clause. Follows <command>CREATE INDEX</command> class="PARAMETER">column_name_index</replaceable> columns and/or
format. <literal>SELECT</> privilege on any column appearing <replaceable class="PARAMETER">expression_index</replaceable>
within <replaceable expressions, and an optional <replaceable class="PARAMETER">
class="PARAMETER">expression_index</replaceable> is required. index_predicate</replaceable>. All <replaceable
</para> class="PARAMETER">table_name</replaceable> unique indexes that,
</listitem> without regard to order, contain exactly the
</varlistentry> <parameter>conflict_target</parameter>-specified
columns/expressions are inferred (chosen) as arbiter indexes. If
<varlistentry> an <replaceable class="PARAMETER">index_predicate</replaceable> is
<term><replaceable class="PARAMETER">collation</replaceable></term> specified, it must, as a further requirement for inference,
<listitem> satisfy arbiter indexes. Note that this means a non-partial
<para> unique index (a unique index without a predicate) will be inferred
When specified, mandates that corresponding <replaceable (and thus used by <literal>ON CONFLICT</literal>) if such an index
class="PARAMETER">column_name_index</replaceable> or satisfying every other criteria is available. If an attempt at
<replaceable class="PARAMETER">expression_index</replaceable> use a inference is unsuccessful, an error is raised.
particular collation in order to be matched in the inference clause. </para>
Typically this is omitted, as collations usually do not affect whether or
not a constraint violation occurs. Follows <command>CREATE <para>
INDEX</command> format. <literal>ON CONFLICT DO UPDATE</literal> guarantees an atomic
</para> <command>INSERT</command> or <command>UPDATE</command> outcome;
</listitem> provided there is no independent error, one of those two outcomes
</varlistentry> is guaranteed, even under high concurrency. This is also known as
<firstterm>UPSERT</firstterm> &mdash; <quote>UPDATE or
<varlistentry> INSERT</quote>.
<term><replaceable class="PARAMETER">opclass</replaceable></term> </para>
<listitem>
<para> <variablelist>
When specified, mandates that corresponding <replaceable <varlistentry>
class="PARAMETER">column_name_index</replaceable> or <term><literal>conflict_target</literal></term>
<replaceable class="PARAMETER">expression_index</replaceable> use <listitem>
particular operator class in order to be matched by the inference <para>
clause. Sometimes this is omitted because the Specifies which conflicts <literal>ON CONFLICT</literal> takes
<emphasis>equality</emphasis> semantics are often equivalent across a the alternative action on by choosing <firstterm>arbiter
type's operator classes anyway, or because it's sufficient to trust that indexes</firstterm>. Either performs <emphasis>unique index
the defined unique indexes have the pertinent definition of equality. inference</emphasis>, or names a constraint explicitly. For
Follows <command>CREATE INDEX</command> format. <literal>ON CONFLICT DO NOTHING</literal>, it is optional to
</para> specify a <parameter>conflict_target</parameter>; when
</listitem> omitted, conflicts with all usable constraints (and unique
</varlistentry> indexes) are handled. For <literal>ON CONFLICT DO
UPDATE</literal>, a <parameter>conflict_target</parameter>
<varlistentry> <emphasis>must</emphasis> be provided.
<term><replaceable class="PARAMETER">index_predicate</replaceable></term> </para>
<listitem> </listitem>
<para> </varlistentry>
Used to allow inference of partial unique indexes. Any indexes
that satisfy the predicate (which need not actually be partial <varlistentry>
indexes) can be matched by the rest of the inference clause. <term><literal>conflict_action</literal></term>
Follows <command>CREATE INDEX</command> format. <listitem>
<literal>SELECT</> privilege on any column appearing within <para>
<replaceable class="PARAMETER">index_predicate</replaceable> is <parameter>conflict_action</parameter> specifies an
required. alternative <literal>ON CONFLICT</literal> action. It can be
</para> either <literal>DO NOTHING</literal>, or a <literal>DO
</listitem> UPDATE</literal> clause specifying the exact details of the
</varlistentry> <literal>UPDATE</literal> action to be performed in case of a
conflict. The <literal>SET</literal> and
<varlistentry> <literal>WHERE</literal> clauses in <literal>ON CONFLICT DO
<term><replaceable class="PARAMETER">constraint_name</replaceable></term> UPDATE</literal> have access to the existing row using the
<listitem> table's name (or an alias), and to rows proposed for insertion
<para> using the special <varname>excluded</varname> table.
Explicitly specifies an arbiter <emphasis>constraint</emphasis> <literal>SELECT</> privilege is required on any column in the
by name, rather than inferring a constraint or index. This is target table where corresponding <varname>excluded</varname>
mostly useful for exclusion constraints, that cannot be chosen columns are read.
in the conventional way (with an inference clause). </para>
</para> <para>
</listitem> Note that the effects of all per-row <literal>BEFORE
</varlistentry> INSERT</literal> triggers are reflected in
<varname>excluded</varname> values, since those effects may
<varlistentry> have contributed to the row being excluded from insertion.
<term><replaceable class="PARAMETER">condition</replaceable></term> </para>
<listitem> </listitem>
<para> </varlistentry>
An expression that returns a value of type <type>boolean</type>. Only
rows for which this expression returns <literal>true</literal> will be <varlistentry>
updated, although all rows will be locked when the <term><replaceable class="PARAMETER">column_name_index</replaceable></term>
<literal>ON CONFLICT DO UPDATE</> action is taken. <listitem>
</para> <para>
</listitem> The name of a <replaceable
</varlistentry> class="PARAMETER">table_name</replaceable> column. Used to
</variablelist> infer arbiter indexes. Follows <command>CREATE
</refsect1> INDEX</command> format. <literal>SELECT</> privilege on
<replaceable class="PARAMETER">column_name_index</replaceable>
<refsect1 id="sql-on-conflict"> is required.
<title id="sql-on-conflict-title"><literal>ON CONFLICT</literal> Clause</title> </para>
<indexterm zone="SQL-INSERT"> </listitem>
<primary>UPSERT</primary> </varlistentry>
</indexterm>
<indexterm zone="SQL-INSERT"> <varlistentry>
<primary>ON CONFLICT</primary> <term><replaceable class="PARAMETER">expression_index</replaceable></term>
</indexterm> <listitem>
<para> <para>
The optional <literal>ON CONFLICT</literal> clause specifies an Similar to <replaceable
alternative action to raising a unique violation or exclusion class="PARAMETER">column_name_index</replaceable>, but used to
constraint violation error. For each individual row proposed for infer expressions on <replaceable
insertion, either the insertion proceeds, or, if a constraint class="PARAMETER">table_name</replaceable> columns appearing
specified by the <parameter>conflict_target</parameter> is within index definitions (not simple columns). Follows
violated, the alternative <parameter>conflict_action</parameter> is <command>CREATE INDEX</command> format. <literal>SELECT</>
taken. privilege on any column appearing within <replaceable
</para> class="PARAMETER">expression_index</replaceable> is required.
</para>
<para> </listitem>
<parameter>conflict_target</parameter> describes which conflicts </varlistentry>
are handled by the <literal>ON CONFLICT</literal> clause. Either a
<emphasis>unique index inference</emphasis> clause or an explicitly <varlistentry>
named constraint can be used. For <literal>ON CONFLICT DO <term><replaceable class="PARAMETER">collation</replaceable></term>
NOTHING</literal>, it is optional to specify a <listitem>
<parameter>conflict_target</parameter>; when omitted, conflicts <para>
with all usable constraints (and unique indexes) are handled. For When specified, mandates that corresponding <replaceable
<literal>ON CONFLICT DO UPDATE</literal>, a conflict target class="PARAMETER">column_name_index</replaceable> or
<emphasis>must</emphasis> be specified. <replaceable class="PARAMETER">expression_index</replaceable>
use a particular collation in order to be matched during
Every time an insertion without <literal>ON CONFLICT</literal> inference. Typically this is omitted, as collations usually
would ordinarily raise an error due to violating one of the do not affect whether or not a constraint violation occurs.
inferred (or explicitly named) constraints, a conflict (as in Follows <command>CREATE INDEX</command> format.
<literal>ON CONFLICT</literal>) occurs, and the alternative action, </para>
as specified by <parameter>conflict_action</parameter> is taken. </listitem>
This happens on a row-by-row basis. </varlistentry>
</para>
<varlistentry>
<para> <term><replaceable class="PARAMETER">opclass</replaceable></term>
A <emphasis>unique index inference</emphasis> clause consists of <listitem>
one or more <replaceable <para>
class="PARAMETER">column_name_index</replaceable> columns and/or When specified, mandates that corresponding <replaceable
<replaceable class="PARAMETER">expression_index</replaceable> class="PARAMETER">column_name_index</replaceable> or
expressions, and an optional <replaceable class="PARAMETER"> <replaceable class="PARAMETER">expression_index</replaceable>
index_predicate</replaceable>. use particular operator class in order to be matched during
</para> inference. Typically this is omitted, as the
<emphasis>equality</emphasis> semantics are often equivalent
<para> across a type's operator classes anyway, or because it's
All the <replaceable class="PARAMETER">table_name</replaceable> sufficient to trust that the defined unique indexes have the
unique indexes that, without regard to order, contain exactly the pertinent definition of equality. Follows <command>CREATE
specified columns/expressions and, if specified, whose predicate INDEX</command> format.
implies the <replaceable class="PARAMETER"> </para>
index_predicate</replaceable> are chosen as arbiter indexes. Note </listitem>
that this means an index without a predicate will be used if a </varlistentry>
non-partial index matching every other criteria happens to be
available. <varlistentry>
</para> <term><replaceable class="PARAMETER">index_predicate</replaceable></term>
<listitem>
<para> <para>
If no index matches the inference clause (nor is there a constraint Used to allow inference of partial unique indexes. Any
explicitly named), an error is raised. Deferred constraints are indexes that satisfy the predicate (which need not actually be
not supported as arbiters. partial indexes) can be inferred. Follows <command>CREATE
</para> INDEX</command> format. <literal>SELECT</> privilege on any
column appearing within <replaceable
<para> class="PARAMETER">index_predicate</replaceable> is required.
<parameter>conflict_action</parameter> defines the action to be </para>
taken in case of conflict. <literal>ON CONFLICT DO </listitem>
NOTHING</literal> simply avoids inserting a row as its alternative </varlistentry>
action. <literal>ON CONFLICT DO UPDATE</literal> updates the
existing row that conflicts with the row proposed for insertion as <varlistentry>
its alternative action. <term><replaceable class="PARAMETER">constraint_name</replaceable></term>
<listitem>
<literal>ON CONFLICT DO UPDATE</literal> guarantees an atomic <para>
<command>INSERT</command> or <command>UPDATE</command> outcome - provided Explicitly specifies an arbiter
there is no independent error, one of those two outcomes is guaranteed, <emphasis>constraint</emphasis> by name, rather than inferring
even under high concurrency. This feature is also known as a constraint or index.
<firstterm>UPSERT</firstterm>. </para>
</listitem>
Note that exclusion constraints are not supported with </varlistentry>
<literal>ON CONFLICT DO UPDATE</literal>.
</para> <varlistentry>
<term><replaceable class="PARAMETER">condition</replaceable></term>
<para> <listitem>
<literal>ON CONFLICT DO UPDATE</literal> optionally accepts <para>
a <literal>WHERE</literal> clause <replaceable>condition</replaceable>. An expression that returns a value of type
When provided, the statement only proceeds with updating if <type>boolean</type>. Only rows for which this expression
the <replaceable>condition</replaceable> is satisfied. Otherwise, unlike a returns <literal>true</literal> will be updated, although all
conventional <command>UPDATE</command>, the row is still locked for update. rows will be locked when the <literal>ON CONFLICT DO UPDATE</>
Note that the <replaceable>condition</replaceable> is evaluated last, after action is taken. Note that
a conflict has been identified as a candidate to update. <replaceable>condition</replaceable> is evaluated last, after
</para> a conflict has been identified as a candidate to update.
</para>
<para> </listitem>
The <literal>SET</literal> and <literal>WHERE</literal> clauses in </varlistentry>
<literal>ON CONFLICT UPDATE</literal> have access to the existing </variablelist>
row, using the table's name, and to the row <para>
proposed for insertion, using the <varname>excluded</varname> Note that exclusion constraints are not supported as arbiters with
alias. The <varname>excluded</varname> alias requires <literal>ON CONFLICT DO UPDATE</literal>. In all cases, only
<literal>SELECT</> privilege on any column whose values are read. <literal>NOT DEFERRABLE</literal> constraints and unique indexes
are supported as arbiters.
Note that the effects of all per-row <literal>BEFORE INSERT</literal> </para>
triggers are reflected in <varname>excluded</varname> values, since those
effects may have contributed to the row being excluded from insertion. <para>
</para> <command>INSERT</command> with an <literal>ON CONFLICT DO UPDATE</>
clause is a <quote>deterministic</quote> statement. This means
<para> that the command will not be allowed to affect any single existing
<command>INSERT</command> with an <literal>ON CONFLICT DO UPDATE</> row more than once; a cardinality violation error will be raised
clause is a <quote>deterministic</quote> statement. This means when this situation arises. Rows proposed for insertion should
that the command will not be allowed to affect any single existing not duplicate each other in terms of attributes constrained by an
row more than once; a cardinality violation error will be raised arbiter index or constraint. Note that exclusion constraints are
when this situation arises. Rows proposed for insertion should not not supported with <literal>ON CONFLICT DO UPDATE</literal>.
duplicate each other in terms of attributes constrained by the </para>
conflict-arbitrating unique index. <tip>
</para> <para>
It is often preferable to use unique index inference rather than
naming a constraint directly using <literal>ON CONFLICT ON
CONSTRAINT</literal> <replaceable class="PARAMETER">
constraint_name</replaceable>. Inference will continue to work
correctly when the underlying index is replaced by another more
or less equivalent index in an overlapping way, for example when
using <literal>CREATE UNIQUE INDEX ... CONCURRENTLY</literal>
before dropping the index being replaced.
</para>
</tip>
</refsect2>
</refsect1> </refsect1>
<refsect1> <refsect1>
...@@ -617,12 +630,12 @@ INSERT INTO employees_log SELECT *, current_timestamp FROM upd; ...@@ -617,12 +630,12 @@ INSERT INTO employees_log SELECT *, current_timestamp FROM upd;
<para> <para>
Insert or update new distributors as appropriate. Assumes a unique Insert or update new distributors as appropriate. Assumes a unique
index has been defined that constrains values appearing in the index has been defined that constrains values appearing in the
<literal>did</literal> column. Note that an <varname>EXCLUDED</> <literal>did</literal> column. Note that the special
expression is used to reference values originally proposed for <varname>excluded</> table is used to reference values originally
insertion: proposed for insertion:
<programlisting> <programlisting>
INSERT INTO distributors (did, dname) INSERT INTO distributors (did, dname)
VALUES (5, 'Gizmo transglobal'), (6, 'Associated Computing, inc') VALUES (5, 'Gizmo Transglobal'), (6, 'Associated Computing, Inc')
ON CONFLICT (did) DO UPDATE SET dname = EXCLUDED.dname; ON CONFLICT (did) DO UPDATE SET dname = EXCLUDED.dname;
</programlisting> </programlisting>
</para> </para>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment