firebird icon indicating copy to clipboard operation
firebird copied to clipboard

Firebird 5.0.2.1613 Windows 32-bit "MERGE INTO" gives wrong returning value with the use of sequence

Open kuola opened this issue 3 months ago • 2 comments

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.

MERGE_INTO_error.txt

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

kuola avatar Sep 18 '25 11:09 kuola

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;

asfernandes avatar Sep 22 '25 01:09 asfernandes

Just to clarify, sama result with FB 5.0.3

TommiPrami avatar Sep 22 '25 10:09 TommiPrami