ON CONFLICT clause
An ON CONFLICT clause specifies the action an SQL insert takes when it violates a uniqueness or exclusion constraint.
DuckDB in Action
An ON CONFLICT clause specifies how an insert or update handles a uniqueness or related constraint conflict.
- How it is used
- Handles duplicate or conflicting rows while inserting or updating relational data.
- How deep it goes
- Explains default and named conflict targets, DO NOTHING, DO UPDATE, excluded values, and computed update expressions.
- Examples
- Demonstrates ignored duplicate IDs, validity-date replacement, and averaged readings keyed by system and timestamp.
- What you can do after
- Apply via DuckDB SQL to ignore duplicates, replace conflicting values, or merge incoming values into existing rows.
Designing AI Systems
The ON CONFLICT clause is a PostgreSQL SQL construct that specifies how an insert should proceed when it violates a uniqueness or exclusion constraint.
- How it is used
- Handles concurrent session creation without turning duplicate identifiers into request failures.
- How deep it goes
- Explains the race condition and resulting timestamp update, but does not detail complete ON CONFLICT syntax.
- Examples
- Uses two concurrent requests submitting the same session ID as the concrete race-condition example.
- What you can do after
- Apply it via PostgreSQL to make get-or-create persistence resilient to duplicate concurrent inserts.
What to know first
- MERGE statementA MERGE statement is an SQL data-modification command that conditionally inserts, updates, or deletes target rows based on source-to-target matches.
- SQLSQL is a standardized declarative language for defining, querying, and manipulating data in relational database systems.
Related concepts
- do nothing clauseused by · A DO NOTHING clause directs a conflicting INSERT operation to discard the conflicting row without raising an error or changing existing data.
- race conditionaddresses · A race condition is a concurrency defect in which program behavior or results depend on the timing or ordering of interacting operations.
- upsertimplements · An upsert is a data-modification operation that updates a matching record or resource, or inserts it when no match exists.
- insertuses · Insertion is an operation that adds an element, record, or value to a data structure or data store.
- MERGE statementalternative to · A MERGE statement is an SQL data-modification command that conditionally inserts, updates, or deletes target rows based on source-to-target matches.
Questions about ON CONFLICT clause
What is ON CONFLICT clause?
An ON CONFLICT clause specifies the action an SQL insert takes when it violates a uniqueness or exclusion constraint.
Which Manning books explain ON CONFLICT clause?
DuckDB in Action and Designing AI Systems.
What should I know before learning ON CONFLICT clause?
Manning books that teach ON CONFLICT clause usually introduce MERGE statement and SQL first.
What is the difference between ON CONFLICT clause and insert or replace?
An ON CONFLICT clause specifies the action an SQL insert takes when it violates a uniqueness or exclusion constraint. INSERT OR REPLACE is SQL shorthand that replaces an existing conflicting row with the inserted row.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

