Search code examples
qtpostgresqldatabase-designpermissions

How to check role of current PostgreSQL user from Qt application?


I have an application (based on the Qt library) which uses QPSQL driver.
In PostgreSQL, there are a few user roles defined (e.g: admin, operator, user). My application creates a connection to the Postgres server under a specified user. How can I check the user's role?


Solution

  • The manual:

    SELECT current_user;  -- user name of current execution context
    SELECT session_user;  -- session user name
    

    Meaning, session_user shows the role you connected with, and current_user shows the role you are currently operating with, for instance after calling SET role some_other_role;.