Skip to content

CREATE SEQUENCE START WITH has wrong initial value [CORE6084] #6334

@firebird-automations

Description

@firebird-automations

Submitted by: @mrotteveel

Relate to CORE6376
Replaces CORE4349

When using CREATE SEQUENCE seq_name START WITH n [INCREMENT BY x], then the first value generated by the sequence is n + x (where x = 1 when the INCREMENT BY clause is absent). This is wrong: the first value produced should be n. See also "9.29 Generation of the next value of a sequence generator" in SQL:2016.

Examples

CREATE SEQUENCE seq_name START WITH 1;
SELECT NEXT VALUE FOR seq_name FROM rdb$database;
-- Result = 2
-- Expected = 1
CREATE SEQUENCE seq_name START WITH 1 INCREMENT BY 2;
SELECT NEXT VALUE FOR seq_name FROM rdb$database;
-- Result = 3
-- Expected = 1
CREATE SEQUENCE seq_name START WITH 1 INCREMENT BY -1;
SELECT NEXT VALUE FOR seq_name FROM rdb$database;
-- Result = 0
-- Expected = 1
CREATE SEQUENCE seq_name START WITH 1 INCREMENT BY -2;
SELECT NEXT VALUE FOR seq_name FROM rdb$database;
-- Result = -1
-- Expected = 1
CREATE SEQUENCE seq_name INCREMENT BY 2;
SELECT NEXT VALUE FOR seq_name FROM rdb$database;
-- Result = 2
-- Expected = 1
CREATE SEQUENCE seq_name INCREMENT BY -1;
SELECT NEXT VALUE FOR seq_name FROM rdb$database;
-- Result = -1
-- Expected = 1
CREATE SEQUENCE seq_name INCREMENT BY -2;
SELECT NEXT VALUE FOR seq_name FROM rdb$database;
-- Result = -2
-- Expected = 1

This problem also affects ALTER SEQUENCE RESTART WITH n (see CORE4349)

Commits: 44660f8 4d1ce73 23dc0c6 FirebirdSQL/fbt-repository@5f4a198 FirebirdSQL/fbt-repository@641376f FirebirdSQL/fbt-repository@70bbf35

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions