Files
email-tracker/external/duckdb/test/sql/upsert/upsert_coverage.test
2025-10-24 19:21:19 -05:00

37 lines
1.0 KiB
SQL

# name: test/sql/upsert/upsert_coverage.test
# group: [upsert]
statement ok
PRAGMA enable_verification;
statement ok
CREATE TABLE tbl (a INT, b INT UNIQUE, c INT UNIQUE, d INT UNIQUE);
statement ok
INSERT INTO tbl (b, c, d) VALUES (1, 2, 3), (2, 3, 1), (3, 1, 2)
# Create conflicts in three existing tuples with one INSERT tuple.
# Each conflict has a different row ID.
# We never have to deal with one-to-many conflicts in anything other than
# a DO NOTHING action. That is because we need a conflict target
# to use any sort of WHERE or SET expression that references the existing table.
statement ok
INSERT INTO tbl(b, c, d) VALUES (3, 3, 3) ON CONFLICT DO NOTHING;
query III
SELECT b, c, d FROM tbl ORDER BY ALL;
----
1 2 3
2 3 1
3 1 2
# We fail without a conflict target.
statement error
INSERT INTO tbl(b, c, d) VALUES (3, 3, 3)
ON CONFLICT DO UPDATE SET b = EXCLUDED.b, c = EXCLUDED.c, d = EXCLUDED.d;
----
<REGEX>:Binder Error.*Conflict target has to be provided for a DO UPDATE operation when the table has multiple UNIQUE/PRIMARY KEY constraints.*