选择 current_user 的群组名称
Selecting groups name of current_user
我使用以下命令检查 PostgreSQL 数据库中用户的组或角色,
select rolname from pg_authid where pg_has_role('some_username', rolname, 'member');
如上所示,我必须在上面的查询中手动输入用户名,如上面的 'some_username'
。
有什么方法可以查询 current_user,我的意思是针对当前连接到数据库的用户。类似于下面的命令,
select rolname from pg_authid where pg_has_role(current_user, rolname, 'member');
此命令无法正常运行。 returns 完成 pg_authid
中的 rolname
列。
要访问 pg_authid
,您需要成为超级用户,因此 current_user
将成为超级用户,并且拥有所有角色。
要在使用非超级用户登录时获取该信息,请使用 pg_roles
Quote from the manual for pg_roles
This is simply a publicly readable view of pg_authid that blanks out the password field.
select rolname
from pg_roles
where pg_has_role(current_user, rolname, 'member');
我使用以下命令检查 PostgreSQL 数据库中用户的组或角色,
select rolname from pg_authid where pg_has_role('some_username', rolname, 'member');
如上所示,我必须在上面的查询中手动输入用户名,如上面的 'some_username'
。
有什么方法可以查询 current_user,我的意思是针对当前连接到数据库的用户。类似于下面的命令,
select rolname from pg_authid where pg_has_role(current_user, rolname, 'member');
此命令无法正常运行。 returns 完成 pg_authid
中的 rolname
列。
要访问 pg_authid
,您需要成为超级用户,因此 current_user
将成为超级用户,并且拥有所有角色。
要在使用非超级用户登录时获取该信息,请使用 pg_roles
Quote from the manual for pg_roles
This is simply a publicly readable view of pg_authid that blanks out the password field.
select rolname
from pg_roles
where pg_has_role(current_user, rolname, 'member');