Skip to Main Content
Practical PostgreSQL
book

Practical PostgreSQL

by Joshua D. Drake, John C. Worsley
January 2002
Intermediate to advanced content levelIntermediate to advanced
640 pages
16h 39m
English
O'Reilly Media, Inc.
Content preview from Practical PostgreSQL

Delete

Removes rows from a table.

Synopsis

DELETE FROM [ ONLY ] table [ WHERE condition ]

Parameters

table

The name of the table from which you are deleting rows.

condition

The condition that identifies rows to be deleted. This is just like the WHERE clause of a SELECT query; refer to the reference entry titled “SELECT” for more information on constructing conditions. Note that not providing a WHERE condition will cause all rows to be deleted from a table.

Results

DELETE count

The message returned when the command is executed. The count is the number of rows that were removed. If that number is 0, then either no rows met the specified condition, or there were no rows in the table to be removed.

Description

Use DELETE to remove rows from a table. Only rows that match a condition you specify will be deleted. To delete all rows from a table, do not specify a condition. Issuing a DELETE with no condition results in all rows being deleted from the target table. You will then be left with an empty table.

Note

Description

Use TRUNCATE to empty a table more efficiently (and explicitly) than with an unconditional DELETE statement.

Use the ONLY clause to prevent the deletion of rows from tables that inherit from the target table. ONLY restricts the delete operation to only the target table. Otherwise, the delete operation will affect not only the target table, but all tables that inherit from it.

Example

The following ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PostgreSQL: Up and Running, 2nd Edition

PostgreSQL: Up and Running, 2nd Edition

Regina O. Obe, Leo S. Hsu
Learning PostgreSQL 11 - Third Edition

Learning PostgreSQL 11 - Third Edition

Christopher Travers, Andrey Volkov
Learn PostgreSQL

Learn PostgreSQL

Luca Ferrari, Enrico Pirozzi
PostgreSQL 13 Cookbook

PostgreSQL 13 Cookbook

Vallarapu Naga Avinash Kumar

Publisher Resources

ISBN: 9781449309770Supplemental ContentErrata Page