🐘 PostgreSQL - DELETE / TRUNCATE
DELETE / TRUNCATE
Updated at 2015-09-24 02:55
All statements works in PostgreSQL 9.1+. For more PostgreSQL notes, check out PostgreSQL Guide
Deleting matching rows.
DELETE
FROM task
WHERE status = 'DONE';
DELETE
FROM film
WHERE producer_id IN (SELECT id
FROM producer
WHERE name = 'foo');
TRUNCATE empties a table and the related tables. Really useful for development and testing.
TRUNCATE some_table CASCADE;
Sources
- PostgreSQL - DELETE
- Postgres Guide
- PostgreSQL documentation