如何从 Qt 应用程序检查当前 PostgreSQL 用户的角色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22501705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to check role of current PostgreSQL user from Qt application?
提问by Alendorff
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?
我有一些基于 Qt 库并使用 QPSQL 驱动程序的应用程序。
在 PostreSQL 中定义了一些用户角色(例如:admin、operator、user)。我的应用程序在指定用户下创建到 postgres 服务器的连接。如何检查用户角色?
回答by Erwin Brandstetter
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;
.
意思是,session_user
显示您连接的角色,并current_user
显示您当前正在操作的角色,例如在调用之后SET role some_other_role;
。
回答by hank
You can check PostgreSQL user permissions with this query:
您可以使用以下查询检查 PostgreSQL 用户权限:
SELECT * FROM pg_roles;