@@ -13678,24 +13678,6 @@ nextval('foo'::text) <lineannotation><literal>foo</literal> is looked up at
13678
13678
see its command reference page for more information.
13679
13679
</para>
13680
13680
13681
- <important>
13682
- <para>
13683
- To avoid blocking concurrent transactions that obtain numbers from
13684
- the same sequence, a <function>nextval</function> operation is never
13685
- rolled back; that is, once a value has been fetched it is considered
13686
- used and will not be returned again. This is true even if the
13687
- surrounding transaction later aborts, or if the calling query ends
13688
- up not using the value. For example an <command>INSERT</command> with
13689
- an <literal>ON CONFLICT</literal> clause will compute the to-be-inserted
13690
- tuple, including doing any required <function>nextval</function>
13691
- calls, before detecting any conflict that would cause it to follow
13692
- the <literal>ON CONFLICT</literal> rule instead. Such cases will leave
13693
- unused <quote>holes</quote> in the sequence of assigned values.
13694
- Thus, <productname>PostgreSQL</productname> sequence objects <emphasis>cannot
13695
- be used to obtain <quote>gapless</quote> sequences</emphasis>.
13696
- </para>
13697
- </important>
13698
-
13699
13681
<para>
13700
13682
This function requires <literal>USAGE</literal>
13701
13683
or <literal>UPDATE</literal> privilege on the sequence.
@@ -13772,13 +13754,6 @@ SELECT setval('foo', 42, false); <lineannotation>Next <function>nextval</func
13772
13754
The result returned by <function>setval</function> is just the value of its
13773
13755
second argument.
13774
13756
</para>
13775
- <important>
13776
- <para>
13777
- Because sequences are non-transactional, changes made by
13778
- <function>setval</function> are not undone if the transaction rolls
13779
- back.
13780
- </para>
13781
- </important>
13782
13757
13783
13758
<para>
13784
13759
This function requires <literal>UPDATE</literal> privilege on the
@@ -13789,6 +13764,42 @@ SELECT setval('foo', 42, false); <lineannotation>Next <function>nextval</func
13789
13764
</variablelist>
13790
13765
</para>
13791
13766
13767
+ <caution>
13768
+ <para>
13769
+ To avoid blocking concurrent transactions that obtain numbers from
13770
+ the same sequence, the value obtained by <function>nextval</function>
13771
+ is not reclaimed for re-use if the calling transaction later aborts.
13772
+ This means that transaction aborts or database crashes can result in
13773
+ gaps in the sequence of assigned values. That can happen without a
13774
+ transaction abort, too. For example an <command>INSERT</command> with
13775
+ an <literal>ON CONFLICT</literal> clause will compute the to-be-inserted
13776
+ tuple, including doing any required <function>nextval</function>
13777
+ calls, before detecting any conflict that would cause it to follow
13778
+ the <literal>ON CONFLICT</literal> rule instead.
13779
+ Thus, <productname>PostgreSQL</productname> sequence
13780
+ objects <emphasis>cannot be used to obtain <quote>gapless</quote>
13781
+ sequences</emphasis>.
13782
+ </para>
13783
+
13784
+ <para>
13785
+ Likewise, sequence state changes made by <function>setval</function>
13786
+ are immediately visible to other transactions, and are not undone if
13787
+ the calling transaction rolls back.
13788
+ </para>
13789
+
13790
+ <para>
13791
+ If the database cluster crashes before committing a transaction
13792
+ containing a <function>nextval</function>
13793
+ or <function>setval</function> call, the sequence state change might
13794
+ not have made its way to persistent storage, so that it is uncertain
13795
+ whether the sequence will have its original or updated state after the
13796
+ cluster restarts. This is harmless for usage of the sequence within
13797
+ the database, since other effects of uncommitted transactions will not
13798
+ be visible either. However, if you wish to use a sequence value for
13799
+ persistent outside-the-database purposes, make sure that the
13800
+ <function>nextval</function> call has been committed before doing so.
13801
+ </para>
13802
+ </caution>
13792
13803
</sect1>
13793
13804
13794
13805