© 2026 Hedgehog Software, LLC

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

RLS policy for linking two tables in query

I have a Table:

Table public.users {
  user_id, //links to table auth.user.id
  role,    //admin, super_admin, user
  email    //links to table auth.users.email
}
Table public.users {
  user_id, //links to table auth.user.id
  role,    //admin, super_admin, user
  email    //links to table auth.users.email
}


I'm Trying to create a policy that allows
auth.uid()
auth.uid()
to edit this table if his role is
admin
admin
of
super_admin
super_admin


I've come up with:

create policy admin_can_edit_policy 
    on public.users
    for update using ( 
        auth.uid() in ( 
            select role from public.users 
                where user_id = auth.uid() 
                and (
                    role = 'admin' 
                    or role = 'super_admin'
                )
                limit 1
        )
    );
create policy admin_can_edit_policy 
    on public.users
    for update using ( 
        auth.uid() in ( 
            select role from public.users 
                where user_id = auth.uid() 
                and (
                    role = 'admin' 
                    or role = 'super_admin'
                )
                limit 1
        )
    );


Not sure why I'm getting syntax errors. Does someone have any insights for me?
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

RLS Query referenced tables
SupabaseSSupabase / help-and-questions
3y ago
RLS Policy
SupabaseSSupabase / help-and-questions
4mo ago
Error Inviting User After RLS Policy Query
SupabaseSSupabase / help-and-questions
4y ago
Restrictive RLS policy
SupabaseSSupabase / help-and-questions
2mo ago