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.

Kindcommand
Example LanguageSQL

📝 Syntax

DELETE FROM <table> [AS <alias>]
[USING <other table> [, ...]]
[WHERE <condition>]
[RETURNING <column or expression>]

⚙️ Parameters

WHEREFilters the rows to delete
USINGOther tables that supply the delete condition
RETURNINGReturns 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

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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏