From 95282d3522f4a35fc0aa6b77110bae1e0d8d207f Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Mon, 6 Aug 2012 15:18:00 -0400 Subject: [PATCH] Warn more vigorously about the non-transactional behavior of sequences. Craig Ringer, edited fairly heavily by me --- doc/src/sgml/datatype.sgml | 14 +++++++++++ doc/src/sgml/func.sgml | 48 ++++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index afc82a25ba..aed2d96bed 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -829,6 +829,20 @@ ALTER SEQUENCE tablename_ + + + Because smallserial, serial and + bigserial are implemented usings sequences, there may + be "holes" or gaps in the sequence of values which appears in the + column, even if no rows are ever deleted. This is a value allocated + from the sequence is still "used up" even if a row containing that + value is never successfully inserted into the table column. This + may happen, for example, if the inserting transaction rolls back. + See nextval() in + for details. + + + Prior to PostgreSQL 7.3, serial diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 157de09b4e..ee42da8025 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -9820,6 +9820,27 @@ nextval('foo'::text) foo is looked up at execute nextval concurrently, each will safely receive a distinct sequence value. + + + If a sequence object has been created with default parameters, + successive nextval calls will return successive + values beginning with 1. Other behaviors can be obtained by using + special parameters in the command; + see its command reference page for more information. + + + + + To avoid blocking concurrent transactions that obtain numbers from the + same sequence, a nextval operation is never + rolled back; that is, once a value has been fetched it is considered + used, even if the transaction that did the + nextval later aborts. This means that aborted + transactions might leave unused holes in the sequence + of assigned values. + + + @@ -9883,31 +9904,18 @@ SELECT setval('foo', 42, false); Next nextval wi The result returned by setval is just the value of its second argument. + + + Because sequences are non-transactional, changes made by + setval are not undone if the transaction rolls + back. + + - - If a sequence object has been created with default parameters, - successive nextval calls will return successive values - beginning with 1. Other behaviors can be obtained by using - special parameters in the command; - see its command reference page for more information. - - - - - To avoid blocking concurrent transactions that obtain numbers from the - same sequence, a nextval operation is never rolled back; - that is, once a value has been fetched it is considered used, even if the - transaction that did the nextval later aborts. This means - that aborted transactions might leave unused holes in the - sequence of assigned values. setval operations are never - rolled back, either. - - - -- 2.40.0