Menu

infinite recursion detected in policy for relation (42P17)
📰

infinite recursion detected in policy for relation (42P17)

DEV Community: postgres·BuiltSafely·about 7 hours ago
#XeHDoFfu
#devtopostgresql#devto#dev#policy#supabase
Reading 0:00
15s threshold

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).…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.