Deleting records
Basic delete (:exec)
Use :exec when the caller only needs rows removed and does not need deleted data back.
sql
-- name: delete_author :exec
DELETE FROM authors
WHERE id = :id;python
async def delete_author(
self,
id: int,
) -> None:
query = """
DELETE FROM authors
WHERE
id = %(id)s
"""
params = {
"id": id,
}
async with self.db.cursor() as cur:
await cur.execute(query, params)
result = None
return resultgo
// coming soonrust
// coming soontypescript
// coming soonDelete and return deleted rows
Use RETURNING when the caller needs the deleted values.
sql
-- name: delete_author_returning :one
DELETE FROM authors
WHERE id = :id
RETURNING *;Generated mapping expands RETURNING * to explicit columns, the same way it handles SELECT * and UPDATE ... RETURNING *.
RETURNING a single column
sql
-- name: delete_author_returning_id :one
DELETE FROM authors
WHERE id = :id
RETURNING id;See Scalar returns.
Related guides
For runtime-composable delete criteria, see: