0
Challenge · 53RLS: The Core

Policy anatomy: USING vs WITH CHECK

Securityused in ~100% of apps

Every Supabase tutorial teaches you "USING is for reading, WITH CHECK is for writing." It is a memorable sentence, it gets you through the first week, and it is wrong in the one case that matters. Get UPDATE wrong and a user can hand their own row to someone else — or, more commonly, your policy silently returns nothing and you spend an afternoon convinced the database is broken.

Core idea. A policy has two clauses that answer two different questions at two different moments. USING asks, of a row that already exists: may you reach this row? WITH CHECK asks, of the values you are proposing: may the row look like that? SELECT and DELETE only ever ask the first. INSERT only ever asks the second. UPDATE asks both — which is why UPDATE is where everyone gets caught.
Playground, this isn't a screenshot
existing row
the row already in the table
USING
may you reach it?
update
WITH CHECK
may it become that?
new row
the values you are proposing

BOTH run, at different moments. USING asks 'may you touch this row?' before the change — fail it and zero rows are affected, silently. WITH CHECK asks 'may it become that?' after — fail it, by giving your row away, and it throws 42501. Omit WITH CHECK and Postgres reuses USING.

The asymmetry that catches everyone: a failing USING clause silently filters — zero rows, no error. A failing WITH CHECK clause throws 42501.
So it is not true that "only INSERT throws": an UPDATE that tries to move a row out of your ownership fails WITH CHECK and raises too. And because three of the four commands can fail in total silence, a broken policy and a working one look identical from the client. Test by asserting on the emptiness.
↑ play a little first, then dig in