DELETE -- Removes rows from a table
DELETE FROM table [ WHERE condition ]
Refer to the SELECT statement for further description of the WHERE clause.
If count is 0, no rows were deleted.
DELETE removes rows which satisfy the WHERE clause from the specified table.
If the condition (WHERE clause) is absent, the effect is to delete all rows in the table. The result is a valid, but empty table. Tip: TRUNCATE is a Postgres extension which provides a faster mechanism to remove all rows from a table.
You must have write access to the table in order to modify it, as well as read access to any table whose values are read in the condition.
Remove all films but musicals:
DELETE FROM films
WHERE kind <> 'Musical';
SELECT * FROM films;
code | title | did | date_prod | kind | len
-------+---------------------------+-----+------------+---------+-------
UA501 | West Side Story | 105 | 1961-01-03 | Musical | 02:32
TC901 | The King and I | 109 | 1956-08-11 | Musical | 02:13
WD101 | Bed Knobs and Broomsticks | 111 | | Musical | 01:57
(3 rows)
Clear the table films:
DELETE FROM films;
SELECT * FROM films;
code | title | did | date_prod | kind | len
------+-------+-----+-----------+------+-----
(0 rows)
SQL92 allows a positioned DELETE statement:
DELETE FROM table WHERE CURRENT OF cursor
where cursor identifies an open cursor. Interactive cursors
in Postgres are read-only.