@ -17115,24 +17115,37 @@ SELECT setval('myseq', 42, false); <lineannotation>Next <function>nextval</fu
<caution>
<caution>
<para>
<para>
To avoid blocking concurrent transactions that obtain numbers from
To avoid blocking concurrent transactions that obtain numbers from
the same sequence, a <function>nextval</function> operation is never
the same sequence, the v alue obtained by <function>nextval</function>
rolled back; that is, once a value has been fetched it is considered
is not reclaimed for re-use if the calling transaction later aborts.
used and will not be returned again. This is true even if the
This means that transaction aborts or database crashes can result in
surrounding transaction later aborts, or if the calling query ends
gaps in the sequence of assigned values. That can happen without a
up not using the value . For example an <command>INSERT</command> with
transaction abort, too . For example an <command>INSERT</command> with
an <literal>ON CONFLICT</literal> clause will compute the to-be-inserted
an <literal>ON CONFLICT</literal> clause will compute the to-be-inserted
tuple, including doing any required <function>nextval</function>
tuple, including doing any required <function>nextval</function>
calls, before detecting any conflict that would cause it to follow
calls, before detecting any conflict that would cause it to follow
the <literal>ON CONFLICT</literal> rule instead. Such cases will leave
the <literal>ON CONFLICT</literal> rule instead.
unused <quote>holes</quote> in the sequence of assigned values.
Thus, <productname>PostgreSQL</productname> sequence
Thus, <productname>PostgreSQL</productname> sequence
objects <emphasis>cannot be used to obtain <quote>gapless</quote>
objects <emphasis>cannot be used to obtain <quote>gapless</quote>
sequences</emphasis>.
sequences</emphasis>.
</para>
</para>
<para>
<para>
Likewise, any sequence state changes made by <function>setval</function>
Likewise, sequence state changes made by <function>setval</function>
are not undone if the transaction rolls back.
are immediately visible to other transactions, and are not undone if
the calling transaction rolls back.
</para>
<para>
If the database cluster crashes before committing a transaction
containing a <function>nextval</function>
or <function>setval</function> call, the sequence state change might
not have made its way to persistent storage, so that it is uncertain
whether the sequence will have its original or updated state after the
cluster restarts. This is harmless for usage of the sequence within
the database, since other effects of uncommitted transactions will not
be visible either. However, if you wish to use a sequence value for
persistent outside-the-database purposes, make sure that the
<function>nextval</function> call has been committed before doing so.
</para>
</para>
</caution>
</caution>