pg_has_role()

一个用于确定用户是否是某个角色的成员的函数

pg_has_role() 是一个系统函数,用于确定数据库用户是否是某个角色(组)的成员。

pg_has_role() 函数于 PostgreSQL 8.1 中添加。

用法

pg_has_role ( [ user NAME or OID, ] role TEXT or OID, privilege TEXT ) → BOOLEAN

privilege” 参数可以是 MEMBERUSAGE

如果未提供用户名或 OID,该函数将返回当前数据库角色的信息。

变更历史

示例

pg_has_role() 的基本执行示例

postgres=# SELECT pg_has_role('pg_read_all_settings', 'MEMBER');
 pg_has_role 
-------------
 t
(1 row)

尝试查询一个不存在的角色

postgres=# SELECT pg_has_role('foo', 'MEMBER');
ERROR:  role "foo" does not exist

尝试查询一个未知的“privilege”类型

postgres=# SELECT pg_has_role('pg_read_all_settings', 'FOO');
ERROR:  unrecognized privilege type: "FOO"

分类

系统函数, 用户和角色

另请参阅

pg_auth_members

反馈

如果您对“pg_has_role()”有任何评论、建议或更正,请在此处 提交