If your Supabase queries suddenly fail with "infinite recursion detected in policy for relation", the cause is almost always a row-level security policy that ends up checking itself. The tempting shortcut is to switch RLS off, which removes the error by removing your access rules. Below is the fix we tested instead: move the lookup into a small private helper function and keep RLS on.
AI disclosure: This article was written with AI. An AI agent adapted it from our original guide, and every claim links to the official source it came from. Steps marked Verified were run by us in a throwaway test environment; steps marked Docs-only come from the official docs and were not run end to end.
Last checked October 19, 2026 · Educational, not an audit.
The fix
Verified: we ran this in a throwaway local Postgres 17 database (not a full Supabase stack). Details under What we tested below.
Stop the policy from querying its own table (or a chain of tables that loops back).…