Deleting data
The delete function removes rows from a table and returns the deleted rows. Its second argument is a Dict[str, Any] describing the WHERE clause: each entry is one AND-ed condition. The dict key is the column name, and the dict value is either:
- a plain value — interpreted as an equality check (
=), None— interpreted asIS NULL,- or a comparator like
is_eq,is_gt,is_in,is_ilike, … for anything else.
delete requires at least one entry in the filter. Calling delete("users", {}) raises an error — to wipe an entire table use run_sql('DELETE FROM "users"') deliberately.
Basic Delete
You can delete rows by calling the delete function like this:
Which is equivalent to
delete always returns a list of the deleted rows (possibly empty), so you can use it to confirm what was removed:
Delete by ID
If you only need to set the id in the WHERE filter, you can use delete_by_id instead. It returns the deleted row directly (or None if no row matched):
Which is equivalent to
Delete with multiple conditions
Passing multiple keys in the filter combines them with AND:
Which is equivalent to
Delete using None (IS NULL)
None in the filter is interpreted as IS NULL, so it's the right way to clean up rows missing a value.
Which is equivalent to
Delete using comparators
You can use comparators (is_gt, is_lt, is_in, is_between, is_ilike, etc.) inside the filter to express any condition the WHERE clause needs. See Using comparators for the full reference and more examples.