DELETE (Delete Rows)
Last updated: 2026-11-04
DELETE (Delete Rows)
DELETE removes rows from a table matching a WHERE condition. It proceeds row by row, fires row-level DELETE triggers, and can hand back the removed rows with RETURNING. To empty an entire table, TRUNCATE is usually far faster.
| Kind | command |
|---|---|
| Example Language | SQL |
📝 Syntax
DELETE FROM <table> [AS <alias>]
[USING <other table> [, ...]]
[WHERE <condition>]
[RETURNING <column or expression>]
⚙️ Parameters
| WHERE | Filters the rows to delete |
|---|---|
| USING | Other tables that supply the delete condition |
| RETURNING | Returns the deleted rows |
Returns:The number of affected rows; with RETURNING, the deleted rows are returned as well.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
DROP TABLE
CREATE TABLE
INSERT 0 3
id | user_name
---+----------
1 | alice
3 | carol
remaining
---------
1
📌 Key Points
- DELETE removes rows one by one and fires row-level DELETE triggers; TRUNCATE does not.
- DELETE only marks rows as dead tuples — the space is reclaimed later by VACUUM.
- A DELETE without WHERE empties the entire table.
- DELETE ... USING filters against another table, e.g. to remove orphan rows that no longer have a parent record.
- Deleting a referenced parent row follows the foreign key's ON DELETE rule (CASCADE removes children, RESTRICT blocks the delete).
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QDoes the disk space come back immediately after DELETE?
ANo. The rows are only marked as dead tuples and the space is reused by VACUUM; only VACUUM FULL rewrites the table and returns the space to the operating system.
QShould I use DELETE or TRUNCATE?
AUse DELETE for partial deletes, trigger firing, or RETURNING; use TRUNCATE to empty a table wholesale — it is much faster and skips row-level triggers.