© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
4 replies
eunjae

row level security stuck with recursive checking with SELECT

Hi all,
I have
rooms
rooms
and
participations
participations
tables. This
participations
participations
has both
room_id
room_id
and
user_id
user_id
. When a user enters a room, a new row is added. You get the idea, right?

I have this function:
create or replace function is_participating(param_room_id uuid)
returns boolean as $$
  select exists
    (
      select 1
      from participations
      where room_id = param_room_id
        and user_id = auth.uid()
        and (role = 'admin' or role = 'user')
        and status = 'granted'
    );
$$ language sql;
create or replace function is_participating(param_room_id uuid)
returns boolean as $$
  select exists
    (
      select 1
      from participations
      where room_id = param_room_id
        and user_id = auth.uid()
        and (role = 'admin' or role = 'user')
        and status = 'granted'
    );
$$ language sql;


But when I use this function for

create policy "Can view participations of rooms where they already participate." on participations for select using (is_participating(room_id));
create policy "Can view participations of rooms where they already participate." on participations for select using (is_participating(room_id));


it falls into infinite recursive loop. What's the smart way to deal with this?
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

Help with row level security
SupabaseSSupabase / help-and-questions
12mo ago
ROW LEVEL SECURITY ISSUE
SupabaseSSupabase / help-and-questions
3y ago
Upsert not working with Row Level Security
SupabaseSSupabase / help-and-questions
3y ago
Stuck with a 403 error - new row violates row-level security policy for table
SupabaseSSupabase / help-and-questions
7mo ago