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-issue-importer opened this issue May 16, 2015 · 6 comments

Comments

@firebird-issue-importer

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-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented May 16, 2015

Commented by: @aafemt

Multiple updates must be prohibited.

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented May 16, 2015

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-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented May 17, 2015

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-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented May 17, 2015

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-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Oct 27, 2015

Modified by: @dyemanov

Fix Version: 3.0.0 [ 10048 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Jan 25, 2016

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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant