SQL postgresql 查询以显示用户的组

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3554484/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 07:18:16  来源:igfitidea点击:

postgresql query to show the groups of a user

sqlpostgresql

提问by Philippe Gonday

If I create a user in a group, like:

如果我在组中创建用户,例如:

create role user_1 login inherit in role group_1;

later, with which query could I retrieve to which group(s) a user belongs to?

稍后,我可以使用哪个查询检索用户所属的组?

采纳答案by Frank Heikens

Check pg_roles, pg_authidand pg_auth_members to get the details about roles.

检查 pg_roles、pg_authid和 pg_auth_members 以获取有关角色的详细信息。

回答by alfonx

Just to give a copy&pastable solution - On PostgreSQL (tested 8.4 and 9.3) you can do:

只是为了提供一个可复制和可粘贴的解决方案 - 在 PostgreSQL(已测试 8.4 和 9.3)上,您可以执行以下操作:

select rolname from pg_user
join pg_auth_members on (pg_user.usesysid=pg_auth_members.member)
join pg_roles on (pg_roles.oid=pg_auth_members.roleid)
where
pg_user.usename='USERNAME';

where USERNAME is the name of the login role you are interested in.

其中 USERNAME 是您感兴趣的登录角色的名称。

回答by John Kloian

From the psql command line:

从 psql 命令行:

\dg

or

或者

\du