Skip to content

Incorrect singleton error with MERGE and RETURNING #6942

@asfernandes

Description

@asfernandes

Test case preparation:

create table r1(
    n1 integer,
    n2 integer
);

insert into r1 values (1, 10);
insert into r1 values (2, 20);

In v5 after #6815 this (correctly) returns one record:

merge into r1
    using (
        select 2 x from rdb$database
        union all
        select 3 x from rdb$database
    ) t
        on r1.n1 = t.x
    when not matched then insert values (3, 30)
    returning n1, n2;

In v4 it fails with:

Statement failed, SQLSTATE = 21000
multiple rows in singleton select

With EXECUTE BLOCK, where singleton is applied even in v5, both v4 and v5 incorrectly raises this error:

set term !;

execute block returns (
    o1 integer,
    o2 integer
)
as
begin
    merge into r1
        using (
            select 2 x from rdb$database
            union all
            select 3 x from rdb$database
        ) t
            on r1.n1 = t.x
        when not matched then insert values (3, 30)
        returning n1, n2 into o1, o2;
end!

set term ;!
Statement failed, SQLSTATE = 21000
multiple rows in singleton select
-At block line: 7, col: 5

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions