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

Commit16a6912

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

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
@@ -802,6 +802,20 @@ ALTER SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceab
802802
the column, so that it will be dropped if the column or table is dropped.
803803
</para>
804804

805+
<note>
806+
<para>
807+
Because <type>smallserial</type>, <type>serial</type> and
808+
<type>bigserial</type> are implemented usings sequences, there may
809+
be "holes" or gaps in the sequence of values which appears in the
810+
column, even if no rows are ever deleted. This is a value allocated
811+
from the sequence is still "used up" even if a row containing that
812+
value is never successfully inserted into the table column. This
813+
may happen, for example, if the inserting transaction rolls back.
814+
See <literal>nextval()</literal> in <xref linkend="functions-sequence">
815+
for details.
816+
</para>
817+
</note>
818+
805819
<note>
806820
<para>
807821
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
@@ -9741,6 +9741,27 @@ nextval('foo'::text) <lineannotation><literal>foo</literal> is looked up at
97419741
execute <function>nextval</function> concurrently, each will safely receive
97429742
a distinct sequence value.
97439743
</para>
9744+
9745+
<para>
9746+
If a sequence object has been created with default parameters,
9747+
successive <function>nextval</function> calls will return successive
9748+
values beginning with 1. Other behaviors can be obtained by using
9749+
special parameters in the <xref linkend="sql-createsequence"> command;
9750+
see its command reference page for more information.
9751+
</para>
9752+
9753+
<important>
9754+
<para>
9755+
To avoid blocking concurrent transactions that obtain numbers from the
9756+
same sequence, a <function>nextval</function> operation is never
9757+
rolled back; that is, once a value has been fetched it is considered
9758+
used, even if the transaction that did the
9759+
<function>nextval</function> later aborts. This means that aborted
9760+
transactions might leave unused <quote>holes</quote> in the sequence
9761+
of assigned values.
9762+
</para>
9763+
</important>
9764+
97449765
</listitem>
97459766
</varlistentry>
97469767

@@ -9804,31 +9825,18 @@ SELECT setval('foo', 42, false); <lineannotation>Next <function>nextval</> wi
98049825
The result returned by <function>setval</function> is just the value of its
98059826
second argument.
98069827
</para>
9828+
<important>
9829+
<para>
9830+
Because sequences are non-transactional, changes made by
9831+
<function>setval</function> are not undone if the transaction rolls
9832+
back.
9833+
</para>
9834+
</important>
98079835
</listitem>
98089836
</varlistentry>
98099837
</variablelist>
98109838
</para>
98119839

9812-
<para>
9813-
If a sequence object has been created with default parameters,
9814-
successive <function>nextval</function> calls will return successive values
9815-
beginning with 1. Other behaviors can be obtained by using
9816-
special parameters in the <xref linkend="sql-createsequence"> command;
9817-
see its command reference page for more information.
9818-
</para>
9819-
9820-
<important>
9821-
<para>
9822-
To avoid blocking concurrent transactions that obtain numbers from the
9823-
same sequence, a <function>nextval</function> operation is never rolled back;
9824-
that is, once a value has been fetched it is considered used, even if the
9825-
transaction that did the <function>nextval</function> later aborts. This means
9826-
that aborted transactions might leave unused <quote>holes</quote> in the
9827-
sequence of assigned values. <function>setval</function> operations are never
9828-
rolled back, either.
9829-
</para>
9830-
</important>
9831-
98329840
</sect1>
98339841

98349842

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp