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.…