Menu

1 / 3

Why SET ROLE fails on Supabase, and the RLS error you hit right after

DEV Community: postgres·Faizan Ahmad·3 days ago
#NKBDARlh
#devtopostgresql#devto#dev#role#select
Long article (1199 words) — no AI summary yet.
Reading 0:00
15s threshold

Our analytics feature turns a question about a form's responses into SQL. We wanted that SQL to run as a role that can read three tables and nothing else, so that a bug in the query builder would hit a permission error instead of someone else's data.

The setup is the textbook one:

create role ai_reader_role nologin ; grant select on public . submissions , public . submission_values , public . form_versions to ai_reader_role ;

Enter fullscreen mode

Exit fullscreen mode

Each query then runs in a read-only transaction that drops to that role:

begin read only ; set local role ai_reader_role ; set local statement_timeout = '5s' ; -- the generated query rollback ;

Enter fullscreen mode

Exit fullscreen mode

On Supabase, the set local role line failed:

ERROR: permission denied to set role "ai_reader_role" (SQLSTATE 42501)

Enter fullscreen mode

Exit fullscreen mode

Why you can't become a role you just created

Two facts combine here.

postgres isn't a superuser on Supabase.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.