firebird
firebird copied to clipboard
Firebird 5.0.2.1613 Windows 32-bit "MERGE INTO" gives wrong returning value with the use of sequence
Execution of "MERGE INTO"-sql gives wrong RETURNING-value when using next generator value in the "USING" section. The inserted value is correct and that inserted value with "RETURNING" is also correct.
I provided an example SQL as an attachment that I ran with isql (with SYSDBA) to a freshly created database to reproduce the error.
I would expect the resulting value to be same for all the returned values, but the sql gives a result of:
TESTID TESTID TESTID
===================== ============ ============
5 4 4
I think this is well know issue and more than just a MERGE thing.
This example increments the sequence two times.
INSERT INTO TEST (TESTID, "YEAR", NAME)
select *
from (
select
NEXT VALUE FOR GEN_TEST id,
2025 yr,
'Test' name
from rdb$database
) x
where x.id > 0
returning testid;
Just to clarify, sama result with FB 5.0.3