On 27/05/2024 14:28, Martijn Tonies (Upscene Productions) wrote:
> The Release Notes say this:
>
> "
> Before Firebird 4.0 a sequence was created with its current value set to
> its starting value (or zero by default). So a sequence with starting
> value = 0 and increment = 1 starts at 1. While such a sequence has the
> same result in Firebird 4.0 (i.e. also starts at 1), the underlying
> implementation is different, thus making other cases different.
>
> Now a sequence is created (or restarted) with its current value set to
> its starting value minus its increment. And the default starting value
> is changed to 1. Then a sequence with starting value = 100 and increment
> = 10 has its first NEXT VALUE equal to 100 now, while it was 110 before.
> Likewise, this sequence has its first GEN_ID(SEQ, 1) equal to 91 now,
> while it was 101 before.
> "
>
>
> Could be me, but I don't find this particularly clear with regards to a
> behavioral change or RESTART WITH differences. :)
The behavioral change is:
CREATE SEQUENCE SEQ_X START WITH 100 INCREMENT BY 10;
or
ALTER SEQUENCE SEQ_X RESTART WITH 100 INCREMENT BY 10;
With Firebird 3.0
(1) NEXT VALUE FOR SEQ_X -> 110 (not SQL compliant!)
(2) GEN_ID(SEQ_X, 1) -> 101
(that is, either (1) or (2) is executed immediately after the CREATE
SEQUENCE or ALTER SEQUENCE)
With Firebird 4.0:
(1) NEXT VALUE FOR SEQ_X -> 100 (SQL compliant!)
(2) GEN_IDX(SEQ_X, 1) -> 91
With this, behaviour (1) is now compliant with the SQL standard, but the
change of behaviour (2) might be unexpected for some, and is the result
of that we needed to "correct" the current value of the sequence so the
NEXT VALUE FOR produces the right result. The alternative was modifying
how sequences were used by considering the current value the next value,
which had far more messy implications, as people sometimes use
GEN_ID(..., 0) to obtain the last generated value.
Mark
--
Mark Rotteveel