Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: MERGE fails with violation of PK./UK on target <T> when source <S> contains two rows with similar key for PK and join condition is <S>.pk_field = <T>.pk_field [CORE4796] #5094

Open
firebird-automations opened this issue May 16, 2015 · 6 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @pavel-zotov

WI-T3.0.0.31839:

SQL> create table tdetl(id int constraint tdetl_pk primary key, pid int); commit;
SQL> set count on;
SQL> merge into tdetl t using ( select 5 as id, 1 as pid from rdb$types rows 2 ) s
CON> on http://t.id=s.id
CON> when matched then update set t.pid = s.pid
CON> when not matched then insert values( http://s.id, s.pid);
Statement failed, SQLSTATE = 23000
violation of PRIMARY or UNIQUE KEY constraint "TDETL_PK" on table "TDETL"
-Problematic key value is ("ID" = 5)
Records affected: 1

WI-V2.5.5.26870:

SQL> set count on;
SQL> merge into tdetl t using ( select 5 as id, 1 as pid from rdb$types rows 2 ) s on http://t.id=s.id when matched then update set t.pid
= s.pid when not matched then insert values( http://s.id, s.pid);
Records affected: 1
SQL> select * from tdetl;

      ID          PID

============ ============
5 1

Records affected: 1
SQL>

@firebird-automations
Copy link
Collaborator Author

Commented by: @aafemt

Multiple updates must be prohibited.

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

In this sample row firstly is INSERTED and after this - UPDATED.
BTW, if we add row before merge, and than run it, no exception occurs (and this merge will update the same record multiple times).

@firebird-automations
Copy link
Collaborator Author

Commented by: @sim1984

This is a consequence of the stability of the cursor. MERGE does not see that we have already inserted a row into a table tdetl. And rightly so. However, the index is seeing.

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

I don't think this is a bug.

Multiple matches for the same source record should be considered a undefined behavior. It must be prohibited, but so far I'm unable to do it myself.

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

Fix Version: 3.0.0 [ 10048 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

Fix Version: 3.0 RC2 [ 10048 ] =>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant