Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALTER SEQUENCE RESTART statement does not conform to SQL standard [CORE4349] #4671

Closed
firebird-automations opened this issue Feb 22, 2014 · 10 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Lukas Eder (lukas.eder)

Is replaced by CORE6084

When I'm running these statements:

create sequence s_author_id
alter sequence s_author_id restart with 1
select next value for s_author_id from "RDB$DATABASE"

I'd expect to get 1 as a result for the last query. However, I get 2. While this matches what is documented in the manual...
http://www.firebirdsql.org/refdocs/langrefupd20-alter-seq.html

... I do believe that this is wrong. Instead, 1 should really be the next value. This observation matches the behaviour of these databases:

- DB2
- H2
- HSQLDB
- Ingres
- PostgreSQL
- SQL Server
- Sybase SQL Anywhere

====== Test Details ======

See test for CORE6084

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

I foresee a minor problem here. RESTART WITH 1 means that the generator is reset to zero. And GEN_ID(G, 0) will surely return zero after such an ALTER. Is this acceptable?

@firebird-automations
Copy link
Collaborator Author

Commented by: Lukas Eder (lukas.eder)

I'm not sure about GEN_ID, but clearly, if I say that I want the first sequence value to be 1 and then I get 2, I'm a bit confused :-)

@firebird-automations
Copy link
Collaborator Author

Commented by: Nick (nick)

>>RESTART WITH 1 means that the generator is reset to zero.
No. It resets to 1.

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

The generated value is incremented before being returned, this is how GEN_ID works and NEXT VALUE FOR follows the same approach. So if you want 1 to be returned after RESTART WITH 1, the counter must be reset to 0.

@firebird-automations
Copy link
Collaborator Author

Commented by: Nick (nick)

>>So if you want 1 to be returned after RESTART WITH 1, the counter must be reset to 0.
if "RESTART WITH 0" then NEXT VALUE FOR = 1 // starts with 1 instead of requested 0
if "RESTART WITH 1" then NEXT VALUE FOR = 2 // starts with 2 instead of requested 1

And another example:

create table objects (
id integer generated by default as identity (START WITH 101),
name varchar(15)
);

I expect that after first insert there will be id = 101. But I get 102.

@firebird-automations
Copy link
Collaborator Author

Commented by: @mrotteveel

This was fixed by CORE6084

@firebird-automations
Copy link
Collaborator Author

Modified by: @mrotteveel

Link: This issue is replaced by CORE6084 [ CORE6084 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @mrotteveel

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 4.0 RC 1 [ 10930 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Resolved [ 5 ]

QA Status: Covered by another test(s)

Test Details: See test for CORE6084

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant