Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit95282d3

Browse files
committed
Warn more vigorously about the non-transactional behavior of sequences.
Craig Ringer, edited fairly heavily by me
1 parentf5f8e71 commit95282d3

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

‎doc/src/sgml/datatype.sgml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,20 @@ ALTER SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceab
829829
the column, so that it will be dropped if the column or table is dropped.
830830
</para>
831831

832+
<note>
833+
<para>
834+
Because <type>smallserial</type>, <type>serial</type> and
835+
<type>bigserial</type> are implemented usings sequences, there may
836+
be "holes" or gaps in the sequence of values which appears in the
837+
column, even if no rows are ever deleted. This is a value allocated
838+
from the sequence is still "used up" even if a row containing that
839+
value is never successfully inserted into the table column. This
840+
may happen, for example, if the inserting transaction rolls back.
841+
See <literal>nextval()</literal> in <xref linkend="functions-sequence">
842+
for details.
843+
</para>
844+
</note>
845+
832846
<note>
833847
<para>
834848
Prior to <productname>PostgreSQL</productname> 7.3, <type>serial</type>

‎doc/src/sgml/func.sgml

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9820,6 +9820,27 @@ nextval('foo'::text) <lineannotation><literal>foo</literal> is looked up at
98209820
execute <function>nextval</function> concurrently, each will safely receive
98219821
a distinct sequence value.
98229822
</para>
9823+
9824+
<para>
9825+
If a sequence object has been created with default parameters,
9826+
successive <function>nextval</function> calls will return successive
9827+
values beginning with 1. Other behaviors can be obtained by using
9828+
special parameters in the <xref linkend="sql-createsequence"> command;
9829+
see its command reference page for more information.
9830+
</para>
9831+
9832+
<important>
9833+
<para>
9834+
To avoid blocking concurrent transactions that obtain numbers from the
9835+
same sequence, a <function>nextval</function> operation is never
9836+
rolled back; that is, once a value has been fetched it is considered
9837+
used, even if the transaction that did the
9838+
<function>nextval</function> later aborts. This means that aborted
9839+
transactions might leave unused <quote>holes</quote> in the sequence
9840+
of assigned values.
9841+
</para>
9842+
</important>
9843+
98239844
</listitem>
98249845
</varlistentry>
98259846

@@ -9883,31 +9904,18 @@ SELECT setval('foo', 42, false); <lineannotation>Next <function>nextval</> wi
98839904
The result returned by <function>setval</function> is just the value of its
98849905
second argument.
98859906
</para>
9907+
<important>
9908+
<para>
9909+
Because sequences are non-transactional, changes made by
9910+
<function>setval</function> are not undone if the transaction rolls
9911+
back.
9912+
</para>
9913+
</important>
98869914
</listitem>
98879915
</varlistentry>
98889916
</variablelist>
98899917
</para>
98909918

9891-
<para>
9892-
If a sequence object has been created with default parameters,
9893-
successive <function>nextval</function> calls will return successive values
9894-
beginning with 1. Other behaviors can be obtained by using
9895-
special parameters in the <xref linkend="sql-createsequence"> command;
9896-
see its command reference page for more information.
9897-
</para>
9898-
9899-
<important>
9900-
<para>
9901-
To avoid blocking concurrent transactions that obtain numbers from the
9902-
same sequence, a <function>nextval</function> operation is never rolled back;
9903-
that is, once a value has been fetched it is considered used, even if the
9904-
transaction that did the <function>nextval</function> later aborts. This means
9905-
that aborted transactions might leave unused <quote>holes</quote> in the
9906-
sequence of assigned values. <function>setval</function> operations are never
9907-
rolled back, either.
9908-
</para>
9909-
</important>
9910-
99119919
</sect1>
99129920

99139921

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp