06
Chapter 6
INSERT, UPDATE, DELETE
Changing data safely. INSERT, UPDATE, DELETE, UPSERT, RETURNING, and the patterns that keep history intact.
In this chapter
15
queries, easy → advanced
- 001INSERT: single row into employeesRead
- 002INSERT: multiple rows at onceRead
- 003INSERT FROM SELECT: copy data between tablesRead
- 004UPDATE: give 10% raise to engineering departmentRead
- 005UPDATE with JOIN (UPDATE FROM syntax)Read
- 006DELETE with JOIN conditionRead
- 007Conditional INSERT with ON CONFLICT DO NOTHINGRead
- 008MERGE statement (PostgreSQL 15+)Read
- 009Batch UPDATE with CTE for complex logicRead
- 010INSERT with RETURNING to get generated IDRead
- 011UPDATE: change order status to shippedRead
- 012Soft delete: mark as deleted instead of removingRead
- 013Bulk INSERT with CTE and SELECTRead
- 014Transactional multi-table INSERTRead
- 015Conditional aggregate UPDATE (normalize data)Read