DELETE

Removes rows from a table. Always use WHERE to avoid deleting all rows. Supports RETURNING and DELETE ... USING joins.

Syntax

postgresql
DELETE FROM table WHERE condition RETURNING cols;

Example

postgresql
DELETE FROM sessions
WHERE expires_at < NOW()
RETURNING id;

-- Delete with join:
DELETE FROM cart_items
USING products p
WHERE cart_items.product_id = p.id
  AND p.discontinued = true;