From 9ddfe034c7d7ee9c4a7dcae1ba37e5e4e5ac2488 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 25 Oct 2007 18:54:03 +0000 Subject: Fix ALTER SEQUENCE so that it does not affect the value of currval() for the sequence. Also, make setval() with is_called = false not affect the currval state, either. Per report from Kris Jurka that an implicit ALTER SEQUENCE OWNED BY unexpectedly caused currval() to become valid. Since this isn't 100% backwards compatible, it will go into HEAD only; I'll put a more limited patch into 8.2. --- doc/src/sgml/func.sgml | 23 ++++++++++++++--------- doc/src/sgml/ref/alter_sequence.sgml | 13 +++++++++++-- 2 files changed, 25 insertions(+), 11 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index c9d665376e4..5feb572de2d 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -1,4 +1,4 @@ - + Functions and Operators @@ -8733,15 +8733,20 @@ nextval('foo'::text) foo is looked up at Reset the sequence object's counter value. The two-parameter - form sets the sequence's last_value field to the specified - value and sets its is_called field to true, - meaning that the next nextval will advance the sequence - before returning a value. In the three-parameter form, - is_called can be set either true or - false. If it's set to false, - the next nextval will return exactly the specified + form sets the sequence's last_value field to the + specified value and sets its is_called field to + true, meaning that the next + nextval will advance the sequence before + returning a value. The value reported by currval is + also set to the specified value. In the three-parameter form, + is_called can be set either true + or false. true has the same effect as + the two-parameter form. If it's set to false, the + next nextval will return exactly the specified value, and sequence advancement commences with the following - nextval. For example, + nextval. Furthermore, the value reported by + currval is not changed in this case (this is a change + from pre-8.3 behavior). For example, SELECT setval('foo', 42); Next nextval will return 43 diff --git a/doc/src/sgml/ref/alter_sequence.sgml b/doc/src/sgml/ref/alter_sequence.sgml index b515ae46016..3c982eee6f1 100644 --- a/doc/src/sgml/ref/alter_sequence.sgml +++ b/doc/src/sgml/ref/alter_sequence.sgml @@ -1,5 +1,5 @@ @@ -114,7 +114,10 @@ ALTER SEQUENCE name SET SCHEMA The optional clause RESTART WITH start changes the - current value of the sequence. + current value of the sequence. This is equivalent to calling the + setval function with is_called = + false: the specified value will be returned by the + next call of nextval. @@ -226,6 +229,12 @@ ALTER SEQUENCE name SET SCHEMA + + ALTER SEQUENCE does not affect the currval + status for the sequence. (Before PostgreSQL + 8.3, it sometimes did.) + + Some variants of ALTER TABLE can be used with sequences as well; for example, to rename a sequence it is also -- cgit v1.2.3