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
postgresql query to show the groups of a user
提问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
回答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