且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Qt应用程序中检查当前PostgreSQL用户的角色?

更新时间:2022-10-22 21:39:08

每个文档:

  SELECT current_user; - 当前执行上下文的用户名
SELECT session_user; - 会话用户名

这意味着, session_user 显示您连接的角色, current_user 显示您当前正在运行的角色,例如在调用 SET角色some_other_role


I have some application based on Qt library and using QPSQL driver.
In PostreSQL defined a few user roles (e.g: admin, operator, user). My application creates a connection to postgres server under specified user. How can I check the users role?

Per documentation:

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

That means, 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.