Switch user in a .SQL for postgresql

36 views Asked by At

Is it possible to do the following step in 1 .SQL file?

  1. create a new role

  2. login as the new role

  3. alter role

1

There are 1 answers

0
Puttsche On

In PostgreSQL, executing all those steps in one single .sql file, isn't directly possible due to how session authentication and role switching work. When you connect to a PostgreSQL database, you authenticate as a specific user for the duration of that connection. You can't change the authenticated user mid-session directly using standard SQL commands.