infinite recursion detected in policy for relation
Supabase error 42P17 "infinite recursion detected in policy for relation"? Two RLS policies check each other. Break the loop with a function.
Last edited October 16, 2026
On this page
What it means in plain English
Two tables' security rules each look at the other table, so Postgres goes round in circles and gives up. Common with 'team' or 'shared list' features.
Find a fix pack
Checklists and prompts for Supabase security, Stripe payments and deploys. Each pack is $24, or $49 for all three.
Likely causes
- Policy on table A queries table B, and table B's policy queries table A.
- A policy on a table queries the same table.
How to fix it, step by step
- Find the two policies involved (Database → Policies).
- Create a
security definerfunction in a non-exposed schema that reads the membership table directly:
create schema if not exists private;
create function private.user_list_ids()
returns setof uuid language sql security definer set search_path = '' stable as $$
select list_id from public.list_members where user_id = (select auth.uid())
$$;
revoke execute on function private.user_list_ids() from public;
grant usage on schema private to authenticated;
grant execute on function private.user_list_ids() to authenticated;
- Rewrite both policies to use
id in (select private.user_list_ids())/list_id in (...). - Never create security definer functions in an exposed schema like
public.
How to check it worked
- Queries on both tables return results without the 42P17 error.
- A non-member still sees nothing.
Sources
Related fixes
Tool to consider: Supabase.
Find a fix pack
Checklists and prompts for Supabase security, Stripe payments and deploys. Each pack is $24, or $49 for all three.