# name: test/sql/upsert/postgres/single_key.test # group: [postgres] statement ok pragma enable_verification; # insert...on conflict do unique index inference statement ok create table insertconflicttest( key int4, fruit text, unique (key) ); # Explain tests statement ok insert into insertconflicttest values (0, 'Bilberry') on conflict (key) do update set fruit = excluded.fruit; # Should display qual actually attributable to internal sequential scan: statement ok insert into insertconflicttest values (0, 'Bilberry') on conflict (key) do update set fruit = excluded.fruit where insertconflicttest.fruit != 'Cawesh'; # With EXCLUDED.* expression in scan node: statement ok insert into insertconflicttest values(0, 'Crowberry') on conflict (key) do update set fruit = excluded.fruit where excluded.fruit != 'Elderberry'; # Does the same, but JSON format shows "Conflict Arbiter Index" as JSON array: statement ok insert into insertconflicttest values (0, 'Bilberry') on conflict (key) do update set fruit = excluded.fruit where insertconflicttest.fruit != 'Lime' returning *; # Fails (no unique index inference specification, required for do update variant): ## -- We accept this because there is only 1 Index on the table -- ## statement ok insert into insertconflicttest values (1, 'Apple') on conflict do update set fruit = excluded.fruit; # inference succeeds: statement ok insert into insertconflicttest values (1, 'Apple') on conflict (key) do update set fruit = excluded.fruit; statement ok insert into insertconflicttest values (2, 'Orange') on conflict (key, key, key) do update set fruit = excluded.fruit; # Succeed, since multi-assignment does not involve subquery: statement ok INSERT INTO insertconflicttest VALUES (1, 'Apple'), (2, 'Orange') ON CONFLICT (key) DO UPDATE SET fruit = excluded.fruit, key = excluded.key; # Give good diagnostic message when EXCLUDED.* spuriously referenced from # RETURNING: ## -- We don't support 'excluded' qualified columns in the RETURNING clause yet -- ## statement error insert into insertconflicttest values (1, 'Apple') on conflict (key) do update set fruit = excluded.fruit RETURNING excluded.fruit; ---- :.*Not implemented Error.*not supported in the RETURNING clause yet.* # Only suggest .* column when inference element misspelled: statement error insert into insertconflicttest values (1, 'Apple') on conflict (keyy) do update set fruit = excluded.fruit; ---- :.*Binder Error.*Table "insertconflicttest" does not have a column.* # Have useful HINT for EXCLUDED.* RTE within UPDATE: statement error insert into insertconflicttest values (1, 'Apple') on conflict (key) do update set fruit = excluded.fruitt; ---- :.*Binder Error.*does not have a column named "fruitt".* # inference fails: statement error insert into insertconflicttest values (3, 'Kiwi') on conflict (key, fruit) do update set fruit = excluded.fruit; ---- :.*Binder Error.*not referenced by a UNIQUE/PRIMARY KEY CONSTRAINT or INDEX.* statement error insert into insertconflicttest values (4, 'Mango') on conflict (fruit, key) do update set fruit = excluded.fruit; ---- :.*Binder Error.*not referenced by a UNIQUE/PRIMARY KEY CONSTRAINT or INDEX.* statement error insert into insertconflicttest values (5, 'Lemon') on conflict (fruit) do update set fruit = excluded.fruit; ---- :.*Binder Error.*not referenced by a UNIQUE/PRIMARY KEY CONSTRAINT or INDEX.* statement error insert into insertconflicttest values (6, 'Passionfruit') on conflict (fruit) do update set fruit = excluded.fruit; ---- :.*Binder Error.*not referenced by a UNIQUE/PRIMARY KEY CONSTRAINT or INDEX.* # Check the target relation can be aliased statement ok insert into insertconflicttest AS ict values (6, 'Passionfruit') on conflict (key) do update set fruit = excluded.fruit; # ok, no reference to target table statement ok insert into insertconflicttest AS ict values (6, 'Passionfruit') on conflict (key) do update set fruit = ict.fruit; # ok, alias # error, references aliased away name statement error insert into insertconflicttest AS ict values (6, 'Passionfruit') on conflict (key) do update set fruit = insertconflicttest.fruit; ---- :.*Binder Error.*Referenced table.*not found.*