E0014 unmatched-conflict-target
ON CONFLICT columns match no unique constraint.
| Code | Name | Category | Default |
|---|---|---|---|
E0014 | unmatched-conflict-target | correctness | error |
What it reports
INSERT ... ON CONFLICT (columns) names columns that are not exactly the columns of the table's primary key, a unique constraint or a unique index. PostgreSQL and SQLite reject the statement ("there is no unique or exclusion constraint matching the ON CONFLICT specification"). It usually means the unique index was never created, or covers more columns than the upsert names.
Example
INSERT INTO users (name, email) VALUES ('Alice', 'a@example.com') ON CONFLICT (name) DO NOTHING;
error[E0014]: No unique constraint or primary key of 'users' matches ON CONFLICT (name)
--> q.sql:1:80
|
1 | INSERT INTO users (name, email) VALUES ('Alice', 'a@example.com') ON CONFLICT (name) DO NOTHING;
| ^^^^
= help: The unique keys of 'users' are (id), (email); add a unique constraint or index on (name)
Fixed:
INSERT INTO users (name, email) VALUES ('Alice', 'a@example.com') ON CONFLICT (email) DO NOTHING;
Notes
Unique keys come from PRIMARY KEY, UNIQUE (in CREATE TABLE or ALTER TABLE) and CREATE UNIQUE INDEX; the column order doesn't matter. Nothing is reported for a table with a partial or expression unique index, for a partition (which gets the unique indexes of its parent), or when a schema statement that may define a unique key could not be parsed.
Configuring
# sqlsift.toml
[rules]
unmatched-conflict-target = "warn" # or "off"
Or for a single line: -- sqlsift:disable E0014. The examples use the schema on the Rules page.