0
Challenge · 19SQL II: Tables, Types & Constraints
RLS primer: open until you close it
Securityused in ~95% of apps
You just spent three concepts making DevLog's posts table refuse bad data — the wrong type, a missing value, a duplicate. None of that protects a single row from the wrong person. The instant you create a table in the public schema, it is a plain Postgres table with no notion of ‘this row belongs to alice.’ Nothing about CREATE TABLE turns that on for you, and — contrary to what a lot of tutorials imply — nothing about writing the SQL yourself turns it on either.
Core idea. A table you create with raw SQL starts with row-level security OFF: every row is visible to anyone the Data API lets reach the table at all, is_public column or no is_public column. Turning on ROW LEVEL SECURITY flips that to the opposite extreme — zero policies means zero access, for everyone except a handful of roles that bypass it entirely. There is no safe middle state until you write an actual policy, which is a different concept (52+). This one is only about knowing which of the two walls you are standing against right now.
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
-- you just ran: create table posts …
Aalice's app
select * from posts#1Why I switched to Postgres
#2Draft: my RLS notesprivate
#3Ships on Fridays
Bbob's app
select * from posts#1Why I switched to Postgres
#2Draft: my RLS notesprivate
#3Ships on Fridays
Bob is reading Alice's private draft. This is the leak.
The table is wide open. The same query hands every row to both identities — Bob is reading Alice's private draft. Nothing is stopping him.
One query. Two identities. Different answers. No
where clause chooses who sees what — the policy does, inside Postgres. You do not yet understand howthat clause works; that is Tiers 9–10. This concept exists to make you want the answer.↑ play a little first, then dig in