BUG #5629: ALTER SEQUENCE foo START execute a RESTART

Started by Alexsander Rosaover 15 years ago15 messagesbugs
Jump to latest
#1Alexsander Rosa
alexsander.rosa@gmail.com

The following bug has been logged online:

Bug reference: 5629
Logged by: Alexsander
Email address: alexsander.rosa@gmail.com
PostgreSQL version: 8.3.11
Operating system: Linux
Description: ALTER SEQUENCE foo START execute a RESTART
Details:

Steps to reproduce:

CREATE SEQUENCE foo;
SELECT setval('foo',12345);
ALTER SEQUENCE foo START WITH 10; -- can't change value
SELECT nextval('foo'); -- it's 10 instead of 12346

Apparently START is executing a RESTART.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alexsander Rosa (#1)
Re: BUG #5629: ALTER SEQUENCE foo START execute a RESTART

"Alexsander" <alexsander.rosa@gmail.com> writes:

CREATE SEQUENCE foo;
SELECT setval('foo',12345);
ALTER SEQUENCE foo START WITH 10; -- can't change value
SELECT nextval('foo'); -- it's 10 instead of 12346

Apparently START is executing a RESTART.

Yup. That's what it's defined to do, pre-8.4.

regards, tom lane

#3Alexsander Rosa
alexsander.rosa@gmail.com
In reply to: Tom Lane (#2)
Re: BUG #5629: ALTER SEQUENCE foo START execute a RESTART

Then the docs are misleading:
http://www.postgresql.org/docs/8.3/static/sql-altersequence.html

According the docs, 8.3 does NOT have a START clause -- only RESTART. I
think a START clause should raise an error at 8.3 servers; there's a chance
of someone run the command in several servers (like a pgdiff) and get
different behaviour for the same command.

2010/8/26 Tom Lane <tgl@sss.pgh.pa.us>

"Alexsander" <alexsander.rosa@gmail.com> writes:

CREATE SEQUENCE foo;
SELECT setval('foo',12345);
ALTER SEQUENCE foo START WITH 10; -- can't change value
SELECT nextval('foo'); -- it's 10 instead of 12346

Apparently START is executing a RESTART.

Yup. That's what it's defined to do, pre-8.4.

regards, tom lane

--
Atenciosamente,
Alexsander da Rosa
Linux User #113925

"Extremismo na defesa da liberdade não é defeito.
Moderação na busca por justiça não é virtude."
-- Barry Goldwater

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alexsander Rosa (#3)
Re: BUG #5629: ALTER SEQUENCE foo START execute a RESTART

Alexsander Rosa <alexsander.rosa@gmail.com> writes:

According the docs, 8.3 does NOT have a START clause -- only RESTART. I
think a START clause should raise an error at 8.3 servers; there's a chance
of someone run the command in several servers (like a pgdiff) and get
different behaviour for the same command.

We're not going to change the behavior like that in stable branches...

regards, tom lane

#5Marko Tiikkaja
marko@joh.to
In reply to: Tom Lane (#4)
Re: BUG #5629: ALTER SEQUENCE foo START execute a RESTART

On 2010-08-27 12:51 AM +0300, Tom Lane wrote:

Alexsander Rosa<alexsander.rosa@gmail.com> writes:

According the docs, 8.3 does NOT have a START clause -- only RESTART. I
think a START clause should raise an error at 8.3 servers; there's a chance
of someone run the command in several servers (like a pgdiff) and get
different behaviour for the same command.

We're not going to change the behavior like that in stable branches...

How about documenting it?

Regards,
Marko Tiikkaja

#6Alexsander Rosa
alexsander.rosa@gmail.com
In reply to: Alexsander Rosa (#1)
Re: BUG #5629: ALTER SEQUENCE foo START execute a RESTART

---------- Forwarded message ----------
From: Alexsander Rosa <alexsander.rosa@gmail.com>
Date: 2010/8/27
Subject: Re: [BUGS] BUG #5629: ALTER SEQUENCE foo START execute a RESTART
To: Tom Lane <tgl@sss.pgh.pa.us>

Let me get this straight: in version 8.3 the ALTER SEQUENCE command has an
*undocumented* [1]http://www.postgresql.org/docs/8.3/static/sql-altersequence.html clause START that is actually an alias for RESTART (i.e.
both reset the sequence value to the value passed by the mandatory
argument). In version 8.4 this behavior was *changed* and, according the
docs [2]http://www.postgresql.org/docs/8.4/static/sql-altersequence.html, START now changes the "default start value" that will be used by
subsequent calls of ALTER SEQUENCE ... RESTART without argument (which is
not mandatory anymore). Is this correct?

Is the 8.3 behavior of ALTER SEQUENCE ... START clause as an alias to
RESTART a known bug (or unintended feature) than cannot be corrected because
it's a stable branch? Who would be using an undocumented buggy clause,
anyway? If it's not being considered a bug, or if it's not going to be
fixed, I think the docs should at least mention this oddity.

[1]: http://www.postgresql.org/docs/8.3/static/sql-altersequence.html
[2]: http://www.postgresql.org/docs/8.4/static/sql-altersequence.html

2010/8/26 Tom Lane <tgl@sss.pgh.pa.us>

Alexsander Rosa <alexsander.rosa@gmail.com> writes:

According the docs, 8.3 does NOT have a START clause -- only RESTART. I
think a START clause should raise an error at 8.3 servers; there's a

chance

of someone run the command in several servers (like a pgdiff) and get
different behaviour for the same command.

We're not going to change the behavior like that in stable branches...

regards, tom lane

--
Atenciosamente,
Alexsander da Rosa
Linux User #113925

"Extremismo na defesa da liberdade não é defeito.
Moderação na busca por justiça não é virtude."
-- Barry Goldwater

--
Atenciosamente,
Alexsander da Rosa
Linux User #113925

"Extremismo na defesa da liberdade não é defeito.
Moderação na busca por justiça não é virtude."
-- Barry Goldwater

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alexsander Rosa (#6)
Re: BUG #5629: ALTER SEQUENCE foo START execute a RESTART

Alexsander Rosa <alexsander.rosa@gmail.com> writes:

Let me get this straight: in version 8.3 the ALTER SEQUENCE command has an
*undocumented* [1] clause START that is actually an alias for RESTART (i.e.
both reset the sequence value to the value passed by the mandatory
argument).

Yeah. I just looked at the old code a bit. This behavior was an
artifact of a sloppy implementation: internally, CREATE SEQUENCE ...
START WITH x did the same thing as ALTER SEQUENCE ... RESTART WITH x, so
the code didn't prevent you from using either spelling in either place.
But it wasn't documented or intended that you should write CREATE
SEQUENCE RESTART or ALTER SEQUENCE START.

As of 8.4 ALTER SEQUENCE START has an actually designed meaning, which
is different from ALTER SEQUENCE RESTART. This wasn't documented as an
incompatibility because the syntax wasn't supposed to exist at all
before that.

I'm not inclined to go and retroactively document that these spellings
are possible but deprecated in the old branches. I think that would
just confuse matters even more.

regards, tom lane

In reply to: Tom Lane (#7)
Re: BUG #5629: ALTER SEQUENCE foo START execute a RESTART

Tom Lane escreveu:

I'm not inclined to go and retroactively document that these spellings
are possible but deprecated in the old branches. I think that would
just confuse matters even more.

Is it worth preventing that sloppy implementation in the old branches?

--
Euler Taveira de Oliveira
http://www.timbira.com/

#9Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Euler Taveira de Oliveira (#8)
Re: BUG #5629: ALTER SEQUENCE foo START execute a RESTART

Excerpts from Euler Taveira de Oliveira's message of mié sep 01 10:18:10 -0400 2010:

Tom Lane escreveu:

I'm not inclined to go and retroactively document that these spellings
are possible but deprecated in the old branches. I think that would
just confuse matters even more.

Is it worth preventing that sloppy implementation in the old branches?

That risks removing a (mis)feature that people are currently depending on.

--
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#10Alexsander Rosa
alexsander.rosa@gmail.com
In reply to: Alvaro Herrera (#9)
Re: BUG #5629: ALTER SEQUENCE foo START execute a RESTART

What about the risk of using ALTER SEQUENCE ... START N in a mixed
environment? In the 8.4.x servers it will work as designed but in the 8.3.x
(and below) servers, instead of issuing an error it will CORRUPT the
sequence value without notice. I understand the point of keeping a
(mis)feature when it's harmless or at least not amibiguous, but this is not
the case here. While the 8.4 behavior -- the correct one -- is a mere
configuration of little consequence, the 8.3 (and below) behavior is an
unexpected RESET. I think it's safer to require the people that was using
old versions with the wrong spell to fix their code than put lots of users
of the current version in risk of using a potentially disastrous command --
when executed in previous versions. Should all 8.4.x (and beyond) users be
forced to check server version before issuing this command?

2010/9/1 Alvaro Herrera <alvherre@commandprompt.com>

Excerpts from Euler Taveira de Oliveira's message of mié sep 01 10:18:10
-0400 2010:

Tom Lane escreveu:

I'm not inclined to go and retroactively document that these spellings
are possible but deprecated in the old branches. I think that would
just confuse matters even more.

Is it worth preventing that sloppy implementation in the old branches?

That risks removing a (mis)feature that people are currently depending on.

--
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

--
Atenciosamente,
Alexsander da Rosa
Linux User #113925

"Extremismo na defesa da liberdade não é defeito.
Moderação na busca por justiça não é virtude."
-- Barry Goldwater

#11Bruce Momjian
bruce@momjian.us
In reply to: Alexsander Rosa (#10)
Re: BUG #5629: ALTER SEQUENCE foo START execute a RESTART

Alexsander Rosa wrote:

What about the risk of using ALTER SEQUENCE ... START N in a mixed
environment? In the 8.4.x servers it will work as designed but in the 8.3.x
(and below) servers, instead of issuing an error it will CORRUPT the
sequence value without notice. I understand the point of keeping a
(mis)feature when it's harmless or at least not amibiguous, but this is not
the case here. While the 8.4 behavior -- the correct one -- is a mere
configuration of little consequence, the 8.3 (and below) behavior is an
unexpected RESET. I think it's safer to require the people that was using
old versions with the wrong spell to fix their code than put lots of users
of the current version in risk of using a potentially disastrous command --
when executed in previous versions. Should all 8.4.x (and beyond) users be
forced to check server version before issuing this command?

Should all 8.3 users be required to retest their applications after a
minor upgrade? No.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

#12Alexsander Rosa
alexsander.rosa@gmail.com
In reply to: Bruce Momjian (#11)
Re: BUG #5629: ALTER SEQUENCE foo START execute a RESTART

Well, if it's not going to be fixed, then at least the docs should be
revised to warn all 8.4+ users to avoid this command and, if it's really
needed, always check the server version before using the ALTER SEQUENCE ...
START command, once it has a potentially hazardous bug that interprets it as
a RESTART in 8.3 version and below.

2010/9/7 Bruce Momjian <bruce@momjian.us>

Alexsander Rosa wrote:

What about the risk of using ALTER SEQUENCE ... START N in a mixed
environment? In the 8.4.x servers it will work as designed but in the

8.3.x

(and below) servers, instead of issuing an error it will CORRUPT the
sequence value without notice. I understand the point of keeping a
(mis)feature when it's harmless or at least not amibiguous, but this is

not

the case here. While the 8.4 behavior -- the correct one -- is a mere
configuration of little consequence, the 8.3 (and below) behavior is an
unexpected RESET. I think it's safer to require the people that was using
old versions with the wrong spell to fix their code than put lots of

users

of the current version in risk of using a potentially disastrous command

--

when executed in previous versions. Should all 8.4.x (and beyond) users

be

forced to check server version before issuing this command?

Should all 8.3 users be required to retest their applications after a
minor upgrade? No.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

--
Atenciosamente,
Alexsander da Rosa
Linux User #113925

"Extremismo na defesa da liberdade não é defeito.
Moderação na busca por justiça não é virtude."
-- Barry Goldwater

#13Bruce Momjian
bruce@momjian.us
In reply to: Alexsander Rosa (#12)
Re: BUG #5629: ALTER SEQUENCE foo START execute a RESTART

Alexsander Rosa wrote:

Well, if it's not going to be fixed, then at least the docs should be
revised to warn all 8.4+ users to avoid this command and, if it's really
needed, always check the server version before using the ALTER SEQUENCE ...
START command, once it has a potentially hazardous bug that interprets it as
a RESTART in 8.3 version and below.

The proper place for such notification is the 8.4 release notes, which
states:

Sequences now contain an additional 'start_value'
column (Zoltan Boszormenyi)

This supports <command>ALTER SEQUENCE ... RESTART.

Which means basically 8.3 didn't have a start field at all.

This is the first complaint I have heard about it. Do you have new
wording to suggest? Perhaps:

In previous releases, START behaved as RESTART.

---------------------------------------------------------------------------

2010/9/7 Bruce Momjian <bruce@momjian.us>

Alexsander Rosa wrote:

What about the risk of using ALTER SEQUENCE ... START N in a mixed
environment? In the 8.4.x servers it will work as designed but in the

8.3.x

(and below) servers, instead of issuing an error it will CORRUPT the
sequence value without notice. I understand the point of keeping a
(mis)feature when it's harmless or at least not amibiguous, but this is

not

the case here. While the 8.4 behavior -- the correct one -- is a mere
configuration of little consequence, the 8.3 (and below) behavior is an
unexpected RESET. I think it's safer to require the people that was using
old versions with the wrong spell to fix their code than put lots of

users

of the current version in risk of using a potentially disastrous command

--

when executed in previous versions. Should all 8.4.x (and beyond) users

be

forced to check server version before issuing this command?

Should all 8.3 users be required to retest their applications after a
minor upgrade? No.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

--
Atenciosamente,
Alexsander da Rosa
Linux User #113925

"Extremismo na defesa da liberdade n?o ? defeito.
Modera??o na busca por justi?a n?o ? virtude."
-- Barry Goldwater

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

#14Alexsander Rosa
alexsander.rosa@gmail.com
In reply to: Bruce Momjian (#13)
Re: BUG #5629: ALTER SEQUENCE foo START execute a RESTART

At 8.4 release notes, item "E.5.3.3.1. TRUNCATE" there's a sentence:
"The start value of a sequence can be changed by ALTER SEQUENCE START WITH.
"

Maybe this sentence should be copied/moved to "E.5.3.4.1. ALTER" with extra
text stating that START, in previous versions, was an (unintended) alias to
RESTART -- with the wording you suggested or something like that. The advise
to check server_version when using this command could be mentioned, also.

2010/9/8 Bruce Momjian <bruce@momjian.us>

Alexsander Rosa wrote:

Well, if it's not going to be fixed, then at least the docs should be
revised to warn all 8.4+ users to avoid this command and, if it's really
needed, always check the server version before using the ALTER SEQUENCE

...

START command, once it has a potentially hazardous bug that interprets it

as

a RESTART in 8.3 version and below.

The proper place for such notification is the 8.4 release notes, which
states:

Sequences now contain an additional 'start_value'
column (Zoltan Boszormenyi)

This supports <command>ALTER SEQUENCE ... RESTART.

Which means basically 8.3 didn't have a start field at all.

This is the first complaint I have heard about it. Do you have new
wording to suggest? Perhaps:

In previous releases, START behaved as RESTART.

---------------------------------------------------------------------------

--
Atenciosamente,
Alexsander da Rosa
Linux User #113925

#15Bruce Momjian
bruce@momjian.us
In reply to: Alexsander Rosa (#14)
Re: BUG #5629: ALTER SEQUENCE foo START execute a RESTART

Alexsander Rosa wrote:

At 8.4 release notes, item "E.5.3.3.1. TRUNCATE" there's a sentence:
"The start value of a sequence can be changed by ALTER SEQUENCE START WITH.
"

Maybe this sentence should be copied/moved to "E.5.3.4.1. ALTER" with extra
text stating that START, in previous versions, was an (unintended) alias to
RESTART -- with the wording you suggested or something like that. The advise
to check server_version when using this command could be mentioned, also.

I don't think we have had enough people confused by this to add that
level of detail.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +