© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•6mo ago•
2 replies
Borislav Borisov

infinite recursion for table company_members

Hello, I've ran into an infinite recursion error that happens when using supabase.select to select company_members or companies.

You should the primary key of the companies table is called vat of type text and has an index created for it.

I'm providing a detailed rls policy list:

1. Policies for company_members:

SELECT:
alter policy "Users can view company members of their companies"
on "public"."company_members"
to public
using (
  ((profile_id = auth.uid()) OR (EXISTS ( SELECT 1
   FROM company_members cm
  WHERE ((cm.profile_id = auth.uid()) AND (cm.is_active = true) AND ((cm.company_vat)::text = (company_members.company_vat)::text)))))
);
alter policy "Users can view company members of their companies"
on "public"."company_members"
to public
using (
  ((profile_id = auth.uid()) OR (EXISTS ( SELECT 1
   FROM company_members cm
  WHERE ((cm.profile_id = auth.uid()) AND (cm.is_active = true) AND ((cm.company_vat)::text = (company_members.company_vat)::text)))))
);

2. Policies for companies:
alter policy "Users can view companies they are members of"
on "public"."companies"
to authenticated
using (
  ((vat)::text IN ( SELECT company_members.company_vat
   FROM company_members
  WHERE (company_members.profile_id = ( SELECT auth.uid() AS uid))))
);
alter policy "Users can view companies they are members of"
on "public"."companies"
to authenticated
using (
  ((vat)::text IN ( SELECT company_members.company_vat
   FROM company_members
  WHERE (company_members.profile_id = ( SELECT auth.uid() AS uid))))
);
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Infinite Recursion RLS policy issues
SupabaseSSupabase / help-and-questions
8mo ago
Infinite Recursion on RLS Policity causes timeout
SupabaseSSupabase / help-and-questions
4w ago
PostgREST Infinite Recursion on Constraint after removing constraint
SupabaseSSupabase / help-and-questions
4mo ago
Custom JWT settings not available? (infinite recursion fix)
SupabaseSSupabase / help-and-questions
8mo ago