{"Entry":{"collection":"func","key":"pg-has-role","name":"pg_has_role","aliases":[],"metadata":{"changed_in":[],"changes":[{"descriptions_changed":false,"doc_overhaul":false,"from":"8.0","group_changed":null,"signatures":{"added":[],"removed":[]},"status":"added","to":"8.1"},{"descriptions_changed":false,"doc_overhaul":true,"from":"12","group_changed":null,"signatures":{"added":[],"removed":[]},"status":"changed","to":"13"},{"descriptions_changed":true,"doc_overhaul":false,"from":"15","group_changed":null,"signatures":{"added":[],"removed":[]},"status":"changed","to":"16"}],"content_hash":"dbcc21b220dffa0b24836c3a772d79345a3d831b1d2e717a8b4004bf85020f72","first_version":"8.1","group":"info","group_label":"System Information Functions And Operators","groups":["info"],"imported_at":"2026-09-27T17:57:29.233215+08:00","last_version":"20","name":"pg_has_role","name_key":"pg_has_role","position":28078,"present_in":["8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"signature":"pg_has_role ( [ user name or oid, ] role text or oid, privilege text ) → boolean","signature_count":1,"slug":"pg-has-role","source_rev":"b7bd9cda","summary":"Does user have privilege for role? Allowable privilege types are MEMBER, USAGE, and SET.","summary_zh":""}},"Definition":{"Collection":"func","Key":"pg-has-role","SourceDatabase":"center","Version":"18","SourceTable":"func","SourceKey":"pg-has-role","SourceRevision":"b7bd9cda","Facts":{"description":"Does user have privilege for role? Allowable privilege types are MEMBER, USAGE, and SET. MEMBER denotes direct or indirect membership in the role without regard to what specific privileges may be conferred. USAGE denotes whether the privileges of the role are immediately available without doing SET ROLE, while SET denotes whether it is possible to change to the role using the SET ROLE command. WITH ADMIN OPTION or WITH GRANT OPTION can be added to any of these privilege types to test whether the ADMIN privilege is held (all six spellings test the same thing). This function does not allow the special case of setting user to public, because the PUBLIC pseudo-role can never be a member of real roles.","description_html":"Does user have privilege for role? Allowable privilege types are \u003ccode class=\"literal\"\u003eMEMBER\u003c/code\u003e, \u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e, and \u003ccode class=\"literal\"\u003eSET\u003c/code\u003e. \u003ccode class=\"literal\"\u003eMEMBER\u003c/code\u003e denotes direct or indirect membership in the role without regard to what specific privileges may be conferred. \u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e denotes whether the privileges of the role are immediately available without doing \u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e, while \u003ccode class=\"literal\"\u003eSET\u003c/code\u003e denotes whether it is possible to change to the role using the \u003ccode class=\"literal\"\u003eSET ROLE\u003c/code\u003e command. \u003ccode class=\"literal\"\u003eWITH ADMIN OPTION\u003c/code\u003e or \u003ccode class=\"literal\"\u003eWITH GRANT OPTION\u003c/code\u003e can be added to any of these privilege types to test whether the \u003ccode class=\"literal\"\u003eADMIN\u003c/code\u003e privilege is held (all six spellings test the same thing). This function does not allow the special case of setting \u003cem class=\"parameter\"\u003e\u003ccode\u003euser\u003c/code\u003e\u003c/em\u003e to \u003ccode class=\"literal\"\u003epublic\u003c/code\u003e, because the PUBLIC pseudo-role can never be a member of real roles.","description_zh":"","description_zh_html":"","doc":{"anchor":"FUNCTIONS-INFO-ACCESS-TABLE","file":"functions-info.html","slug":"18"},"group":"info","group_label":"System Information Functions And Operators","lang":"en","layout":"table-new","pages":["functions-info.html"],"prose_only":false,"signatures":[{"description":"Does user have privilege for role? Allowable privilege types are MEMBER, USAGE, and SET. MEMBER denotes direct or indirect membership in the role without regard to what specific privileges may be conferred. USAGE denotes whether the privileges of the role are immediately available without doing SET ROLE, while SET denotes whether it is possible to change to the role using the SET ROLE command. WITH ADMIN OPTION or WITH GRANT OPTION can be added to any of these privilege types to test whether the ADMIN privilege is held (all six spellings test the same thing). This function does not allow the special case of setting user to public, because the PUBLIC pseudo-role can never be a member of real roles.","description_html":"Does user have privilege for role? Allowable privilege types are \u003ccode class=\"literal\"\u003eMEMBER\u003c/code\u003e, \u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e, and \u003ccode class=\"literal\"\u003eSET\u003c/code\u003e. \u003ccode class=\"literal\"\u003eMEMBER\u003c/code\u003e denotes direct or indirect membership in the role without regard to what specific privileges may be conferred. \u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e denotes whether the privileges of the role are immediately available without doing \u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e, while \u003ccode class=\"literal\"\u003eSET\u003c/code\u003e denotes whether it is possible to change to the role using the \u003ccode class=\"literal\"\u003eSET ROLE\u003c/code\u003e command. \u003ccode class=\"literal\"\u003eWITH ADMIN OPTION\u003c/code\u003e or \u003ccode class=\"literal\"\u003eWITH GRANT OPTION\u003c/code\u003e can be added to any of these privilege types to test whether the \u003ccode class=\"literal\"\u003eADMIN\u003c/code\u003e privilege is held (all six spellings test the same thing). This function does not allow the special case of setting \u003cem class=\"parameter\"\u003e\u003ccode\u003euser\u003c/code\u003e\u003c/em\u003e to \u003ccode class=\"literal\"\u003epublic\u003c/code\u003e, because the PUBLIC pseudo-role can never be a member of real roles.","description_zh":"","description_zh_html":"","examples":[],"html":"\u003ccode class=\"function\"\u003epg_has_role\u003c/code\u003e ( [ \u003cspan class=\"optional\"\u003e\u003cem class=\"parameter\"\u003e\u003ccode\u003euser\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003ename\u003c/code\u003e or \u003ccode class=\"type\"\u003eoid\u003c/code\u003e,\u003c/span\u003e ] \u003cem class=\"parameter\"\u003e\u003ccode\u003erole\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003etext\u003c/code\u003e or \u003ccode class=\"type\"\u003eoid\u003c/code\u003e, \u003cem class=\"parameter\"\u003e\u003ccode\u003eprivilege\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003etext\u003c/code\u003e ) → \u003ccode class=\"returnvalue\"\u003eboolean\u003c/code\u003e","returns":"boolean","text":"pg_has_role ( [ user name or oid, ] role text or oid, privilege text ) → boolean","zh_from":""}],"zh_from":""},"ManualEvidence":{"doc":{"anchor":"FUNCTIONS-INFO-ACCESS-TABLE","file":"functions-info.html","slug":"18"}},"MeasuredEvidence":{}},"Text":{"Collection":"func","Key":"pg-has-role","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"pg_has_role","Summary":"用户是否具有角色权限？允许的权限类型为MEMBER、USAGE和SET。MEMBER表示对该角色的直接或间接成员资格，而不考虑由此授予的具体权限。USAGE表示该角色的权限是否无需执行SET ROLE即可立即使用，而SET表示是否可以使用SET ROLE命令切换到该角色。任一权限类型后面都可以附加WITH ADMIN OPTION或WITH GRANT OPTION，用于测试是否持有 ADMIN 权限（这六种写法测试的都是同一件事）。此函数不允许将user设置为public这一特殊情况，因为 PUBLIC 伪角色永远不能成为实际角色的成员。","BodyHTML":"用户是否具有角色权限？允许的权限类型为\u003ccode\u003eMEMBER\u003c/code\u003e、\u003ccode\u003eUSAGE\u003c/code\u003e和\u003ccode\u003eSET\u003c/code\u003e。\u003ccode\u003eMEMBER\u003c/code\u003e表示对该角色的直接或间接成员资格，而不考虑由此授予的具体权限。\u003ccode\u003eUSAGE\u003c/code\u003e表示该角色的权限是否无需执行\u003ccode\u003eSET ROLE\u003c/code\u003e即可立即使用，而\u003ccode\u003eSET\u003c/code\u003e表示是否可以使用\u003ccode\u003eSET ROLE\u003c/code\u003e命令切换到该角色。任一权限类型后面都可以附加\u003ccode\u003eWITH ADMIN OPTION\u003c/code\u003e或\u003ccode\u003eWITH GRANT OPTION\u003c/code\u003e，用于测试是否持有 \u003ccode\u003eADMIN\u003c/code\u003e 权限（这六种写法测试的都是同一件事）。此函数不允许将\u003cem\u003e\u003ccode\u003euser\u003c/code\u003e\u003c/em\u003e设置为\u003ccode\u003epublic\u003c/code\u003e这一特殊情况，因为 PUBLIC 伪角色永远不能成为实际角色的成员。\u003cpre\u003epg_has_role ( [ user name or oid, ] role text or oid, privilege text ) → boolean\u003c/pre\u003e用户是否具有角色权限？允许的权限类型为\u003ccode\u003eMEMBER\u003c/code\u003e、\u003ccode\u003eUSAGE\u003c/code\u003e和\u003ccode\u003eSET\u003c/code\u003e。\u003ccode\u003eMEMBER\u003c/code\u003e表示对该角色的直接或间接成员资格，而不考虑由此授予的具体权限。\u003ccode\u003eUSAGE\u003c/code\u003e表示该角色的权限是否无需执行\u003ccode\u003eSET ROLE\u003c/code\u003e即可立即使用，而\u003ccode\u003eSET\u003c/code\u003e表示是否可以使用\u003ccode\u003eSET ROLE\u003c/code\u003e命令切换到该角色。任一权限类型后面都可以附加\u003ccode\u003eWITH ADMIN OPTION\u003c/code\u003e或\u003ccode\u003eWITH GRANT OPTION\u003c/code\u003e，用于测试是否持有 \u003ccode\u003eADMIN\u003c/code\u003e 权限（这六种写法测试的都是同一件事）。此函数不允许将\u003cem\u003e\u003ccode\u003euser\u003c/code\u003e\u003c/em\u003e设置为\u003ccode\u003epublic\u003c/code\u003e这一特殊情况，因为 PUBLIC 伪角色永远不能成为实际角色的成员。","SourceRevision":"1b5ca64c","ContentHash":"9d0c1c5e6e3ba3b87b1d5af157392a6cf5123176716d0b6d58ecc9431f6d6596","Payload":{"description_zh":"用户是否具有角色权限？允许的权限类型为MEMBER、USAGE和SET。MEMBER表示对该角色的直接或间接成员资格，而不考虑由此授予的具体权限。USAGE表示该角色的权限是否无需执行SET ROLE即可立即使用，而SET表示是否可以使用SET ROLE命令切换到该角色。任一权限类型后面都可以附加WITH ADMIN OPTION或WITH GRANT OPTION，用于测试是否持有 ADMIN 权限（这六种写法测试的都是同一件事）。此函数不允许将user设置为public这一特殊情况，因为 PUBLIC 伪角色永远不能成为实际角色的成员。","description_zh_html":"用户是否具有角色权限？允许的权限类型为\u003ccode class=\"literal\"\u003eMEMBER\u003c/code\u003e、\u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e和\u003ccode class=\"literal\"\u003eSET\u003c/code\u003e。\u003ccode class=\"literal\"\u003eMEMBER\u003c/code\u003e表示对该角色的直接或间接成员资格，而不考虑由此授予的具体权限。\u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e表示该角色的权限是否无需执行\u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e即可立即使用，而\u003ccode class=\"literal\"\u003eSET\u003c/code\u003e表示是否可以使用\u003ccode class=\"literal\"\u003eSET ROLE\u003c/code\u003e命令切换到该角色。任一权限类型后面都可以附加\u003ccode class=\"literal\"\u003eWITH ADMIN OPTION\u003c/code\u003e或\u003ccode class=\"literal\"\u003eWITH GRANT OPTION\u003c/code\u003e，用于测试是否持有 \u003ccode class=\"literal\"\u003eADMIN\u003c/code\u003e 权限（这六种写法测试的都是同一件事）。此函数不允许将\u003cem class=\"parameter\"\u003e\u003ccode\u003euser\u003c/code\u003e\u003c/em\u003e设置为\u003ccode class=\"literal\"\u003epublic\u003c/code\u003e这一特殊情况，因为 PUBLIC 伪角色永远不能成为实际角色的成员。","signatures":[{"description_zh":"用户是否具有角色权限？允许的权限类型为MEMBER、USAGE和SET。MEMBER表示对该角色的直接或间接成员资格，而不考虑由此授予的具体权限。USAGE表示该角色的权限是否无需执行SET ROLE即可立即使用，而SET表示是否可以使用SET ROLE命令切换到该角色。任一权限类型后面都可以附加WITH ADMIN OPTION或WITH GRANT OPTION，用于测试是否持有 ADMIN 权限（这六种写法测试的都是同一件事）。此函数不允许将user设置为public这一特殊情况，因为 PUBLIC 伪角色永远不能成为实际角色的成员。","description_zh_html":"用户是否具有角色权限？允许的权限类型为\u003ccode class=\"literal\"\u003eMEMBER\u003c/code\u003e、\u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e和\u003ccode class=\"literal\"\u003eSET\u003c/code\u003e。\u003ccode class=\"literal\"\u003eMEMBER\u003c/code\u003e表示对该角色的直接或间接成员资格，而不考虑由此授予的具体权限。\u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e表示该角色的权限是否无需执行\u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e即可立即使用，而\u003ccode class=\"literal\"\u003eSET\u003c/code\u003e表示是否可以使用\u003ccode class=\"literal\"\u003eSET ROLE\u003c/code\u003e命令切换到该角色。任一权限类型后面都可以附加\u003ccode class=\"literal\"\u003eWITH ADMIN OPTION\u003c/code\u003e或\u003ccode class=\"literal\"\u003eWITH GRANT OPTION\u003c/code\u003e，用于测试是否持有 \u003ccode class=\"literal\"\u003eADMIN\u003c/code\u003e 权限（这六种写法测试的都是同一件事）。此函数不允许将\u003cem class=\"parameter\"\u003e\u003ccode\u003euser\u003c/code\u003e\u003c/em\u003e设置为\u003ccode class=\"literal\"\u003epublic\u003c/code\u003e这一特殊情况，因为 PUBLIC 伪角色永远不能成为实际角色的成员。","returns":"boolean","text":"pg_has_role ( [ user name or oid, ] role text or oid, privilege text ) → boolean","zh_from":"doc"}],"zh_from":"doc"}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":[{"Version":"18","Ordinal":0,"Hash":"49f1c129743a0d508348c3c28d5c9840f7abb1bb2ad60246025d7229ceeacfa4","Text":"pg_has_role ( [ user name or oid, ] role text or oid, privilege text ) → boolean","Returns":"boolean","Payload":{"description":"Does user have privilege for role? Allowable privilege types are MEMBER, USAGE, and SET. MEMBER denotes direct or indirect membership in the role without regard to what specific privileges may be conferred. USAGE denotes whether the privileges of the role are immediately available without doing SET ROLE, while SET denotes whether it is possible to change to the role using the SET ROLE command. WITH ADMIN OPTION or WITH GRANT OPTION can be added to any of these privilege types to test whether the ADMIN privilege is held (all six spellings test the same thing). This function does not allow the special case of setting user to public, because the PUBLIC pseudo-role can never be a member of real roles.","description_html":"Does user have privilege for role? Allowable privilege types are \u003ccode class=\"literal\"\u003eMEMBER\u003c/code\u003e, \u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e, and \u003ccode class=\"literal\"\u003eSET\u003c/code\u003e. \u003ccode class=\"literal\"\u003eMEMBER\u003c/code\u003e denotes direct or indirect membership in the role without regard to what specific privileges may be conferred. \u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e denotes whether the privileges of the role are immediately available without doing \u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e, while \u003ccode class=\"literal\"\u003eSET\u003c/code\u003e denotes whether it is possible to change to the role using the \u003ccode class=\"literal\"\u003eSET ROLE\u003c/code\u003e command. \u003ccode class=\"literal\"\u003eWITH ADMIN OPTION\u003c/code\u003e or \u003ccode class=\"literal\"\u003eWITH GRANT OPTION\u003c/code\u003e can be added to any of these privilege types to test whether the \u003ccode class=\"literal\"\u003eADMIN\u003c/code\u003e privilege is held (all six spellings test the same thing). This function does not allow the special case of setting \u003cem class=\"parameter\"\u003e\u003ccode\u003euser\u003c/code\u003e\u003c/em\u003e to \u003ccode class=\"literal\"\u003epublic\u003c/code\u003e, because the PUBLIC pseudo-role can never be a member of real roles.","description_zh":"","description_zh_html":"","examples":[],"html":"\u003ccode class=\"function\"\u003epg_has_role\u003c/code\u003e ( [ \u003cspan class=\"optional\"\u003e\u003cem class=\"parameter\"\u003e\u003ccode\u003euser\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003ename\u003c/code\u003e or \u003ccode class=\"type\"\u003eoid\u003c/code\u003e,\u003c/span\u003e ] \u003cem class=\"parameter\"\u003e\u003ccode\u003erole\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003etext\u003c/code\u003e or \u003ccode class=\"type\"\u003eoid\u003c/code\u003e, \u003cem class=\"parameter\"\u003e\u003ccode\u003eprivilege\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003etext\u003c/code\u003e ) → \u003ccode class=\"returnvalue\"\u003eboolean\u003c/code\u003e","returns":"boolean","text":"pg_has_role ( [ user name or oid, ] role text or oid, privilege text ) → boolean","zh_from":""}}],"Spellings":null,"SQLState":null,"Evidence":null}
