Skip to content

sql: unique partial indexes do not work correctly with INSERT ON CONFLICT #52603

@mgartner

Description

@mgartner

Below, the second row should be inserted because there is no conflict possible when b is 0.

root@127.0.0.1:53772/defaultdb> create table t (a int, b int, s string, unique index (a) where b > 0);
CREATE TABLE

Time: 6.058ms

root@127.0.0.1:53772/defaultdb> insert into t values (1, 1, 'foo') on conflict (a) do update set s = 'conflict';
INSERT 1

Time: 1.82ms

root@127.0.0.1:53772/defaultdb> select * from t;
  a | b |  s
----+---+------
  1 | 1 | foo
(1 row)

Time: 613µs

root@127.0.0.1:53772/defaultdb> insert into t values (1, 0, 'foo2') on conflict (a) do update set s = 'conflict';
INSERT 1

Time: 1.85ms

root@127.0.0.1:53772/defaultdb> select * from t;
  a | b |    s
----+---+-----------
  1 | 1 | conflict
(1 row)

Time: 599µs

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-partial-indexesRelating to partial indexes.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions