row level security stuck with recursive checking with SELECT

Hi all,
I haverooms and participations tables. This participations has both room_id and 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;


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));


it falls into infinite recursive loop. What's the smart way to deal with this?
Was this page helpful?