FirebirdSQL / firebird

Firebird server, client and tools
https://firebirdsql.org
1.26k stars 217 forks source link

`unknown ISC error 335545269` during merge #8300

Closed atronah closed 2 weeks ago

atronah commented 2 weeks ago

Brief

Merge raises exception unknown ISC error 335545269 if few lines of using dataset match one row in target table and in that few lines one of updated fields has different values.

Steps to reproduce

Create test table

create table mds_test_merge (
    id bigint
    , text varchar(16)
    , constraint pk_mds_test_merge primary key (id)
);

Insert a test row into the test table

insert into mds_test_merge (id,text) values (1,'old');

Try to use merge and get error

merge into mds_test_merge as cur
    using (
        select 1 as id, 'new' as text from rdb$database union
        select 1 as id, 'super new' as text from rdb$database
    ) as upd
    on cur.id = upd.id
    when matched then update set text = upd.text;

because in using dataset we have two rows with id=1 but with different text.

aafemt commented 2 weeks ago

You obviously use an outdated fbclient and firebird.msg:

SQL> merge into mds_test_merge as cur
CON>     using (
CON>         select 1 as id, 'new' as text from rdb$database union
CON>         select 1 as id, 'super new' as text from rdb$database
CON>     ) as upd
CON>     on cur.id = upd.id
CON>     when matched then update set text = upd.text;
Statement failed, SQLSTATE = 21000
Multiple source records cannot match the same target during MERGE
atronah commented 2 weeks ago

Thanks