SQL
`ON CONFLICT` Clause
An `ON CONFLICT` clause can be used to perform a certain action on conflicts that arise from `UNIQUE` or `PRIMARY KEY` constraints.
An example for such a conflict is shown in the following example:  
```sql
CREATE TABLE tbl (i INTEGER PRIMARY KEY, j INTEGER);
INSERT INTO tbl
VALUES (1, 42);
INSERT INTO tbl
VALUES (1, 84);
```  
This raises as an error:  
```console
Constraint Error: Duplicate key "i: 1" violates primary key constraint.
```  
The table will contain the row that was first inserted:  
```sql
SELECT * FROM tbl;
```  
| i | j  |
|--:|---:|
| 1 | 42 |  
These error messages can be avoided by explicitly handling conflicts.
DuckDB supports two such clauses: [`ON CONFLICT DO NOTHING`](#::do-nothing-clause) and [`ON CONFLICT DO UPDATE SET ...`](#::do-update-clause-upsert).  
#### `DO NOTHING` Clause {#docs:sql:statements:insert::do-nothing-clause}  
The `DO NOTHING` clause causes the error(s) to be ignored, and the values are not inserted or updated.
For example:  
```sql
CREATE TABLE tbl (i INTEGER PRIMARY KEY, j INTEGER);
INSERT INTO tbl
VALUES (1, 42);
INSERT INTO tbl
VALUES (1, 84)
ON CONFLICT DO NOTHING;
```  
These statements finish successfully and leaves the table with the row `<i: 1, j: 42>`.