Skip to main content
Modifying rows with diesel::update. Portable Diesel on the DuckDB backend.

Updating columns

diesel::update(target).set(...) where target is a filtered table. Set one column, or a tuple of columns:
.execute returns the number of rows changed.
diesel::update(products::table) with no .filter updates every row. Always scope the target with .filter(...) unless a table-wide update is truly intended.

Expressions in SET

The right-hand side can reference columns and DuckDB scalar functions, not just literals:
See the DSL overview for the function library.

Updating from a struct

A #[derive(AsChangeset)] struct turns into the SET clause. Option fields that are None are omitted from the clause — a convenient partial-update pattern:
See Schema for deriving AsChangeset.
To treat a None as “set this column to NULL” rather than “leave it alone”, add #[diesel(treat_none_as_null = true)] to the AsChangeset struct — this is Diesel’s own attribute.

Returning updated values

Chain .returning(...) with get_result/get_results to read columns back after the update:
See RETURNING.

See also

Delete

Remove rows.

Upsert

Insert-or-update in one statement.

RETURNING

Read values back from an update.

DSL overview

Functions usable in a SET expression.