liveBook · Manning

ON CONFLICT clause

An ON CONFLICT clause specifies the action an SQL insert takes when it violates a uniqueness or exclusion constraint.

How 2 Manning books explain it

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.

Read how DuckDB in Action explains ON CONFLICT clause →

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.

Read how Designing AI Systems explains ON CONFLICT clause →

What to know first

Related concepts

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.