Skip to main content
Removing rows with diesel::delete. Portable Diesel on the DuckDB backend.

Deleting matching rows

Pass a filtered table to diesel::delete:
.execute returns the number of rows deleted. DuckDB-only predicates work in the filter once the DSL prelude is imported — see Operators:

Deleting all rows

A delete with no filter removes every row:
This is the single most common accidental data loss in Diesel. diesel::delete(table) without .filter truncates the table. Scope every delete with .filter(...) unless you really mean “delete everything”.

Returning deleted values

Chain .returning(...) with get_result/get_results to read columns from the rows that were deleted:
See RETURNING.

See also

Update

Modify rows instead of removing them.

RETURNING

Read values back from a delete.

Transactions

Make a multi-step delete atomic.

Select

Preview what a filter matches before deleting.