Learn to change data safely in PostgreSQL — adding rows with INSERT, correcting them with UPDATE, removing them with DELETE and TRUNCATE, and merging with UPSERT. You will wrap risky changes in transactions with BEGIN, COMMIT, ROLLBACK and savepoints so every modification is deliberate and reversible.
Watch the free preview
INSERT basics — single and multiple rows — free to watch, no account needed.
What you'll learn
- Change data safely with INSERT, UPDATE and DELETE and reversible transactions
- Insert single and multiple rows and capture generated values with RETURNING
- Update and delete precisely using a WHERE clause, and clear tables with TRUNCATE
- Merge rows idempotently with UPSERT using ON CONFLICT
- Control transactions and partial rollbacks with BEGIN, COMMIT, ROLLBACK and savepoints
Syllabus
Adding Rows with INSERT
INSERT basics — single and multiple rowsFree preview
RETURNING and inserting from a query
Updating and Deleting Data
UPDATE with a WHERE clause
DELETE and TRUNCATE
Merging Data with UPSERT
ON CONFLICT DO NOTHING and DO UPDATE
Bulk UPSERT and keeping imports idempotent
Transactions and ACID
Transactions — BEGIN, COMMIT and ROLLBACK
Savepoints and partial rollbacks
Lab — 10 Exercises & Solutions
Exercises 1–5
Exercises 6–10