0
Challenge · 17SQL II: Tables, Types & Constraints
INSERT, UPDATE, DELETE & RETURNING
SQLused in ~100% of apps
Every button in DevLog that isn't a page load — Publish, Save draft, Delete — ends its journey as one of these three statements. And every one of them hides a small trap: an UPDATE or DELETE with no WHERE clause is syntactically valid, silently correct, and rewrites or erases the entire table. Postgres will not stop you. Nothing will, except the habit you build right now.
Core idea. INSERT adds rows, UPDATE rewrites the columns of rows that match a WHERE, DELETE removes rows that match a WHERE — and appending RETURNING to any of the three hands back the exact rows Postgres touched, including every value the database computed for you (a generated id, a DEFAULT, now()), in the same round trip. That last part is not a bonus feature: it is what `supabase.from('posts').insert(...).select()` compiles to.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
insert into posts (user_id, title) values (:alice, 'Hello DevLog') returning id, title, created_at, like_count;
the table, after
#1Why I switched to Postgres8♥
#2Draft: RLS notes0♥
#3Hello DevLog0♥
returning
id: 3 (identity)
title: 'Hello DevLog'
created_at: 2026-07-10T... (now())
like_count: 0 (DEFAULT)
You supplied user_id and title. Postgres invents the rest — id from the identity sequence, created_at from now(), like_count from its DEFAULT — and RETURNING is the only way to see them without a second query.
↑ play a little first, then dig in