liveBook · Manning

Idempotency

As explained in DuckDB in Action

Idempotence is the property that repeating an operation produces the same effective result as performing it once.

Idempotency makes repeating an operation produce the same effective result as running it once. In SQL, a repeated insert can fail on a primary-key conflict, so conflict handling makes the statement repeatable—but not necessarily correct. section 3.4.1

Use the conflict strategy that matches the intended workflow:

  • Use ON CONFLICT DO NOTHING to suppress a duplicate primary-key error. section 3.4.1
  • Avoid explicit generated IDs and name inserted columns so repeats do not depend on fragile column order. section 3.4.1
  • Use ON CONFLICT on a business key with DO UPDATE when newer data should replace the existing value. section 3.4.1
  • INSTALL and LOAD commands for DuckDB extensions are themselves idempotent and can be issued repeatedly. section 2.4

Repeatable price loading

INSERT INTO prices(value, valid_from, valid_until) VALUES (11.47, '2019-01-01', '2019-02-01') ON CONFLICT (valid_from) DO UPDATE SET value = excluded.value; section 3.4.1

INSERT INTO prices
VALUES (1, 11.59, '2018-12-01', '2019-01-01')
ON CONFLICT DO NOTHING;

Inspect the minimal repeatable insert that ignores an existing conflict, then compare it with update-based handling. section 3.4.1

How DuckDB in Action covers it

How deep it goes
Explains duplicate-key failure, conflict suppression, and conflict updates, but stops short of general workflow design.
Examples
Demonstrates duplicate price inserts, DO NOTHING, business-key updates, and repeated INSTALL and LOAD commands.
What it assumes
Assumes familiarity with tables, INSERT statements, primary keys, and unique constraints.
What you can do after
Apply it via DuckDB SQL by selecting conflict behavior that either ignores duplicates or updates existing business-keyed rows.
How it connects
Connects idempotency to INSERT statements, primary keys, unique constraints, conflict handling, generated IDs, and database extensions.

Also explained in

Compare how 17 books explain idempotency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of DuckDB in Action. The section links point to the parts of the book it draws on.