{"Entry":{"collection":"sql","key":"set-role","name":"SET ROLE","aliases":["set-role"],"metadata":{"aliases":["set-role"],"changed_in":["9.0"],"changes":[{"from":"8.0","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"added","synopsis":null,"to":"8.1"},{"from":"8.2","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description"],"removed":[]},"status":"changed","synopsis":null,"to":"8.3"},{"from":"8.3","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["notes"],"removed":[]},"status":"changed","synopsis":null,"to":"8.4"},{"from":"8.4","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description"],"removed":[]},"status":"changed","synopsis":{"added":["SET [ SESSION | LOCAL ] ROLE role_name"],"removed":["SET [ SESSION | LOCAL ] ROLE rolename"]},"to":"9.0"},{"from":"9.3","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["notes"],"removed":[]},"status":"changed","synopsis":null,"to":"9.4"},{"from":"9.5","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","notes"],"removed":[]},"status":"changed","synopsis":null,"to":"9.6"},{"from":"15","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","notes"],"removed":[]},"status":"changed","synopsis":null,"to":"16"},{"from":"16","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","notes"],"removed":[]},"status":"changed","synopsis":null,"to":"17"}],"content_hash":"e7ec37ff194b6f55b520590c014f4934e1b4e2d8f94ee702c5a68a81a3687a11","editorial":{},"first_version":"8.1","group":"role","imported_at":"2026-09-30T17:43:38.258303+08:00","last_version":"20","name":"SET ROLE","object":"ROLE","position":5015,"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"],"purpose":"set the current user identifier of the current session","purpose_zh":"","related":["set-session-authorization"],"slug":"set-role","source_rev":"a709ab85","synopsis":"SET [ SESSION | LOCAL ] ROLE role_name\nSET [ SESSION | LOCAL ] ROLE NONE\nRESET ROLE","verb":"SET"}},"Definition":{"Collection":"sql","Key":"set-role","SourceDatabase":"center","Version":"18","SourceTable":"sqlcmd","SourceKey":"set-role","SourceRevision":"a709ab85","Facts":{"anchor":"SQL-SET-ROLE","file":"sql-set-role.html","lang":"en","name":"SET ROLE","purpose":"set the current user identifier of the current session","purpose_zh":"","related":["set-session-authorization"],"sections":[{"html":"\u003cp\u003eThis command sets the current user identifier of the current SQL session to be \u003cem class=\"replaceable\"\u003e\u003ccode\u003erole_name\u003c/code\u003e\u003c/em\u003e. The role name can be written as either an identifier or a string literal. After \u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e, permissions checking for SQL commands is carried out as though the named role were the one that had logged in originally. Note that \u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e and \u003ccode class=\"command\"\u003eSET SESSION AUTHORIZATION\u003c/code\u003e are exceptions; permissions checks for those continue to use the current session user and the initial session user (the \u003cem class=\"firstterm\"\u003eauthenticated user\u003c/em\u003e), respectively.\u003c/p\u003e\u003cp\u003eThe current session user must have the \u003ccode class=\"literal\"\u003eSET\u003c/code\u003e option for the specified \u003cem class=\"replaceable\"\u003e\u003ccode\u003erole_name\u003c/code\u003e\u003c/em\u003e, either directly or indirectly via a chain of memberships with the \u003ccode class=\"literal\"\u003eSET\u003c/code\u003e option. (If the session user is a superuser, any role can be selected.)\u003c/p\u003e\u003cp\u003eThe \u003ccode class=\"literal\"\u003eSESSION\u003c/code\u003e and \u003ccode class=\"literal\"\u003eLOCAL\u003c/code\u003e modifiers act the same as for the regular \u003ca href=\"/docs/18/sql-set.html\" title=\"SET\"\u003e\u003ccode class=\"command\"\u003eSET\u003c/code\u003e\u003c/a\u003e command.\u003c/p\u003e\u003cp\u003e\u003ccode class=\"literal\"\u003eSET ROLE NONE\u003c/code\u003e sets the current user identifier to the current session user identifier, as returned by \u003ccode class=\"function\"\u003esession_user\u003c/code\u003e. \u003ccode class=\"literal\"\u003eRESET ROLE\u003c/code\u003e sets the current user identifier to the connection-time setting specified by the \u003ca href=\"/docs/18/libpq-connect.html#LIBPQ-CONNECT-OPTIONS\"\u003ecommand-line options\u003c/a\u003e, \u003ca href=\"/docs/18/sql-alterrole.html\" title=\"ALTER ROLE\"\u003e\u003ccode class=\"command\"\u003eALTER ROLE\u003c/code\u003e\u003c/a\u003e, or \u003ca href=\"/docs/18/sql-alterdatabase.html\" title=\"ALTER DATABASE\"\u003e\u003ccode class=\"command\"\u003eALTER DATABASE\u003c/code\u003e\u003c/a\u003e, if any such settings exist. Otherwise, \u003ccode class=\"literal\"\u003eRESET ROLE\u003c/code\u003e sets the current user identifier to the current session user identifier. These forms can be executed by any user.\u003c/p\u003e","key":"description","title":"Description"},{"html":"\u003cp\u003eUsing this command, it is possible to either add privileges or restrict one's privileges. If the session user role has been granted memberships \u003ccode class=\"literal\"\u003eWITH INHERIT TRUE\u003c/code\u003e, it automatically has all the privileges of every such role. In this case, \u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e effectively drops all the privileges except for those which the target role directly possesses or inherits. On the other hand, if the session user role has been granted memberships \u003ccode class=\"literal\"\u003eWITH INHERIT FALSE\u003c/code\u003e, the privileges of the granted roles can't be accessed by default. However, if the role was granted \u003ccode class=\"literal\"\u003eWITH SET TRUE\u003c/code\u003e, the session user can use \u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e to drop the privileges assigned directly to the session user and instead acquire the privileges available to the named role. If the role was granted \u003ccode class=\"literal\"\u003eWITH INHERIT FALSE, SET FALSE\u003c/code\u003e then the privileges of that role cannot be exercised either with or without \u003ccode class=\"literal\"\u003eSET ROLE\u003c/code\u003e.\u003c/p\u003e\u003cp\u003e\u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e has effects comparable to \u003ca href=\"/docs/18/sql-set-session-authorization.html\" title=\"SET SESSION AUTHORIZATION\"\u003e\u003ccode class=\"command\"\u003eSET SESSION AUTHORIZATION\u003c/code\u003e\u003c/a\u003e, but the privilege checks involved are quite different. Also, \u003ccode class=\"command\"\u003eSET SESSION AUTHORIZATION\u003c/code\u003e determines which roles are allowable for later \u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e commands, whereas changing roles with \u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e does not change the set of roles allowed to a later \u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e.\u003c/p\u003e\u003cp\u003e\u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e does not process session variables as specified by the role's \u003ca href=\"/docs/18/sql-alterrole.html\" title=\"ALTER ROLE\"\u003e\u003ccode class=\"command\"\u003eALTER ROLE\u003c/code\u003e\u003c/a\u003e settings; this only happens during login.\u003c/p\u003e\u003cp\u003e\u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e cannot be used within a \u003ccode class=\"literal\"\u003eSECURITY DEFINER\u003c/code\u003e function.\u003c/p\u003e","key":"notes","title":"Notes"},{"html":"\u003cpre class=\"programlisting\"\u003eSELECT SESSION_USER, CURRENT_USER;\n\n session_user | current_user\n--------------+--------------\n peter        | peter\n\nSET ROLE 'paul';\n\nSELECT SESSION_USER, CURRENT_USER;\n\n session_user | current_user\n--------------+--------------\n peter        | paul\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003e\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e allows identifier syntax (\u003ccode class=\"literal\"\u003e\"\u003cem class=\"replaceable\"\u003e\u003ccode\u003erolename\u003c/code\u003e\u003c/em\u003e\"\u003c/code\u003e), while the SQL standard requires the role name to be written as a string literal. SQL does not allow this command during a transaction; \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e does not make this restriction because there is no reason to. The \u003ccode class=\"literal\"\u003eSESSION\u003c/code\u003e and \u003ccode class=\"literal\"\u003eLOCAL\u003c/code\u003e modifiers are a \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e extension, as is the \u003ccode class=\"literal\"\u003eRESET\u003c/code\u003e syntax.\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/set-session-authorization/?v=18\" title=\"SET SESSION AUTHORIZATION\"\u003e\u003cspan class=\"refentrytitle\"\u003eSET SESSION AUTHORIZATION\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","slug":"18","synopsis_html":"SET [ SESSION | LOCAL ] ROLE \u003cem class=\"replaceable\"\u003e\u003ccode\u003erole_name\u003c/code\u003e\u003c/em\u003e\nSET [ SESSION | LOCAL ] ROLE NONE\nRESET ROLE","synopsis_text":"SET [ SESSION | LOCAL ] ROLE role_name\nSET [ SESSION | LOCAL ] ROLE NONE\nRESET ROLE"},"ManualEvidence":{},"MeasuredEvidence":{}},"Text":{"Collection":"sql","Key":"set-role","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"SET ROLE","Summary":"设置当前会话的当前用户标识符","BodyHTML":"\u003cpre\u003eSET [ SESSION | LOCAL ] ROLE role_name\nSET [ SESSION | LOCAL ] ROLE NONE\nRESET ROLE\u003c/pre\u003e\u003csection\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e这个命令将当前 SQL 会话的当前用户标识符设置为 \u003cem\u003e\u003ccode\u003erole_name\u003c/code\u003e\u003c/em\u003e。角色名既可以写成标识符，也可以写成字符串字面量。执行\u003ccode\u003eSET ROLE\u003c/code\u003e之后，对 SQL 命令的权限检查会按照最初登录的就是该角色那样进行。注意，\u003ccode\u003eSET ROLE\u003c/code\u003e和 \u003ccode\u003eSET SESSION AUTHORIZATION\u003c/code\u003e是例外：对这两个命令的权限检查，分别仍然使用当前会话用户和初始会话用户（即\u003cem\u003e已认证用户\u003c/em\u003e）。\u003c/p\u003e\u003cp\u003e当前会话用户必须对指定的 \u003cem\u003e\u003ccode\u003erole_name\u003c/code\u003e\u003c/em\u003e拥有\u003ccode\u003eSET\u003c/code\u003e选项，这可以是直接拥有，也可以通过带有\u003ccode\u003eSET\u003c/code\u003e选项的成员关系链间接拥有。（如果会话用户是超级用户，则可以选择任意角色。）\u003c/p\u003e\u003cp\u003e\u003ccode\u003eSESSION\u003c/code\u003e和\u003ccode\u003eLOCAL\u003c/code\u003e修饰符的作用与常规的 \u003ca href=\"/docs/18/sql-set.html\" title=\"SET\" rel=\"nofollow\"\u003e\u003ccode\u003eSET\u003c/code\u003e\u003c/a\u003e命令相同。\u003c/p\u003e\u003cp\u003e\u003ccode\u003eSET ROLE NONE\u003c/code\u003e将当前用户标识符设置为当前会话用户标识符，即\u003ccode\u003esession_user\u003c/code\u003e返回的值。如果存在此类设置，\u003ccode\u003eRESET ROLE\u003c/code\u003e会将当前用户标识符设置为连接建立时由\u003ca href=\"/docs/18/libpq-connect.html#LIBPQ-CONNECT-OPTIONS\" rel=\"nofollow\"\u003e命令行选项\u003c/a\u003e、\u003ca href=\"/docs/18/sql-alterrole.html\" title=\"ALTER ROLE\" rel=\"nofollow\"\u003e\u003ccode\u003eALTER ROLE\u003c/code\u003e\u003c/a\u003e或 \u003ca href=\"/docs/18/sql-alterdatabase.html\" title=\"ALTER DATABASE\" rel=\"nofollow\"\u003e\u003ccode\u003eALTER DATABASE\u003c/code\u003e\u003c/a\u003e指定的设置。否则，\u003ccode\u003eRESET ROLE\u003c/code\u003e会将当前用户标识符设置为当前会话用户标识符。这些形式可以由任何用户执行。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e注解\u003c/h2\u003e\u003cp\u003e使用这个命令，既可以增加权限，也可以限制自己的权限。如果会话用户角色获得的是\u003ccode\u003eWITH INHERIT TRUE\u003c/code\u003e的成员关系，它会自动拥有每个此类角色的全部权限。在这种情况下，\u003ccode\u003eSET ROLE\u003c/code\u003e实际上会去掉除目标角色直接拥有或继承而来的权限之外的所有权限。另一方面，如果会话用户角色获得的是\u003ccode\u003eWITH INHERIT FALSE\u003c/code\u003e的成员关系，默认就不能使用被授予角色的权限。但是，如果该角色是以 \u003ccode\u003eWITH SET TRUE\u003c/code\u003e授予的，则会话用户可以使用 \u003ccode\u003eSET ROLE\u003c/code\u003e放弃直接分配给自己的权限，转而获得该角色可用的权限。如果该角色是以\u003ccode\u003eWITH INHERIT FALSE, SET FALSE\u003c/code\u003e授予的，那么无论是否使用\u003ccode\u003eSET ROLE\u003c/code\u003e，该角色的权限都无法行使。\u003c/p\u003e\u003cp\u003e\u003ccode\u003eSET ROLE\u003c/code\u003e的效果与 \u003ca href=\"/docs/18/sql-set-session-authorization.html\" title=\"SET SESSION AUTHORIZATION\" rel=\"nofollow\"\u003e\u003ccode\u003eSET SESSION AUTHORIZATION\u003c/code\u003e\u003c/a\u003e相近，但其中涉及的权限检查完全不同。此外，\u003ccode\u003eSET SESSION AUTHORIZATION\u003c/code\u003e会决定后续 \u003ccode\u003eSET ROLE\u003c/code\u003e命令允许使用哪些角色，而通过 \u003ccode\u003eSET ROLE\u003c/code\u003e更改角色并不会改变后续 \u003ccode\u003eSET ROLE\u003c/code\u003e允许使用的角色集合。\u003c/p\u003e\u003cp\u003e\u003ccode\u003eSET ROLE\u003c/code\u003e不会处理角色的 \u003ca href=\"/docs/18/sql-alterrole.html\" title=\"ALTER ROLE\" rel=\"nofollow\"\u003e\u003ccode\u003eALTER ROLE\u003c/code\u003e\u003c/a\u003e设置所指定的会话变量；这只会在登录期间发生。\u003c/p\u003e\u003cp\u003e\u003ccode\u003eSET ROLE\u003c/code\u003e不能在 \u003ccode\u003eSECURITY DEFINER\u003c/code\u003e函数中使用。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e示例\u003c/h2\u003e\u003cpre\u003eSELECT SESSION_USER, CURRENT_USER;\n\n session_user | current_user\n--------------+--------------\n peter        | peter\n\nSET ROLE \u0026#39;paul\u0026#39;;\n\nSELECT SESSION_USER, CURRENT_USER;\n\n session_user | current_user\n--------------+--------------\n peter        | paul\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e兼容性\u003c/h2\u003e\u003cp\u003e\u003cspan\u003ePostgreSQL\u003c/span\u003e允许使用标识符语法（\u003ccode\u003e\u0026#34;\u003cem\u003e\u003ccode\u003erolename\u003c/code\u003e\u003c/em\u003e\u0026#34;\u003c/code\u003e），而 SQL 标准要求将角色名写成字符串字面量。SQL 不允许在事务中执行这个命令；\u003cspan\u003ePostgreSQL\u003c/span\u003e不施加这一限制，因为没有理由这样做。\u003ccode\u003eSESSION\u003c/code\u003e和\u003ccode\u003eLOCAL\u003c/code\u003e修饰符，以及 \u003ccode\u003eRESET\u003c/code\u003e语法，都是\u003cspan\u003ePostgreSQL\u003c/span\u003e扩展。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e另见\u003c/h2\u003e\u003cspan\u003e\u003ca href=\"/wiki/sql/set-session-authorization/?v=18\" title=\"SET SESSION AUTHORIZATION\" rel=\"nofollow\"\u003e\u003cspan\u003eSET SESSION AUTHORIZATION\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","SourceRevision":"1b5ca64c","ContentHash":"f8eadd0accc5d71642e1b006327a8515bf939b49d6c38798f09e550a2504fb5d","Payload":{"purpose_zh":"设置当前会话的当前用户标识符","sections":[{"html":"\u003cp\u003e这个命令将当前 SQL 会话的当前用户标识符设置为 \u003cem class=\"replaceable\"\u003e\u003ccode\u003erole_name\u003c/code\u003e\u003c/em\u003e。角色名既可以写成标识符，也可以写成字符串字面量。执行\u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e之后，对 SQL 命令的权限检查会按照最初登录的就是该角色那样进行。注意，\u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e和 \u003ccode class=\"command\"\u003eSET SESSION AUTHORIZATION\u003c/code\u003e是例外：对这两个命令的权限检查，分别仍然使用当前会话用户和初始会话用户（即\u003cem class=\"firstterm\"\u003e已认证用户\u003c/em\u003e）。\u003c/p\u003e\u003cp\u003e当前会话用户必须对指定的 \u003cem class=\"replaceable\"\u003e\u003ccode\u003erole_name\u003c/code\u003e\u003c/em\u003e拥有\u003ccode class=\"literal\"\u003eSET\u003c/code\u003e选项，这可以是直接拥有，也可以通过带有\u003ccode class=\"literal\"\u003eSET\u003c/code\u003e选项的成员关系链间接拥有。（如果会话用户是超级用户，则可以选择任意角色。）\u003c/p\u003e\u003cp\u003e\u003ccode class=\"literal\"\u003eSESSION\u003c/code\u003e和\u003ccode class=\"literal\"\u003eLOCAL\u003c/code\u003e修饰符的作用与常规的 \u003ca href=\"/docs/18/sql-set.html\" title=\"SET\"\u003e\u003ccode class=\"command\"\u003eSET\u003c/code\u003e\u003c/a\u003e命令相同。\u003c/p\u003e\u003cp\u003e\u003ccode class=\"literal\"\u003eSET ROLE NONE\u003c/code\u003e将当前用户标识符设置为当前会话用户标识符，即\u003ccode class=\"function\"\u003esession_user\u003c/code\u003e返回的值。如果存在此类设置，\u003ccode class=\"literal\"\u003eRESET ROLE\u003c/code\u003e会将当前用户标识符设置为连接建立时由\u003ca href=\"/docs/18/libpq-connect.html#LIBPQ-CONNECT-OPTIONS\"\u003e命令行选项\u003c/a\u003e、\u003ca href=\"/docs/18/sql-alterrole.html\" title=\"ALTER ROLE\"\u003e\u003ccode class=\"command\"\u003eALTER ROLE\u003c/code\u003e\u003c/a\u003e或 \u003ca href=\"/docs/18/sql-alterdatabase.html\" title=\"ALTER DATABASE\"\u003e\u003ccode class=\"command\"\u003eALTER DATABASE\u003c/code\u003e\u003c/a\u003e指定的设置。否则，\u003ccode class=\"literal\"\u003eRESET ROLE\u003c/code\u003e会将当前用户标识符设置为当前会话用户标识符。这些形式可以由任何用户执行。\u003c/p\u003e","key":"description","title":"描述"},{"html":"\u003cp\u003e使用这个命令，既可以增加权限，也可以限制自己的权限。如果会话用户角色获得的是\u003ccode class=\"literal\"\u003eWITH INHERIT TRUE\u003c/code\u003e的成员关系，它会自动拥有每个此类角色的全部权限。在这种情况下，\u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e实际上会去掉除目标角色直接拥有或继承而来的权限之外的所有权限。另一方面，如果会话用户角色获得的是\u003ccode class=\"literal\"\u003eWITH INHERIT FALSE\u003c/code\u003e的成员关系，默认就不能使用被授予角色的权限。但是，如果该角色是以 \u003ccode class=\"literal\"\u003eWITH SET TRUE\u003c/code\u003e授予的，则会话用户可以使用 \u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e放弃直接分配给自己的权限，转而获得该角色可用的权限。如果该角色是以\u003ccode class=\"literal\"\u003eWITH INHERIT FALSE, SET FALSE\u003c/code\u003e授予的，那么无论是否使用\u003ccode class=\"literal\"\u003eSET ROLE\u003c/code\u003e，该角色的权限都无法行使。\u003c/p\u003e\u003cp\u003e\u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e的效果与 \u003ca href=\"/docs/18/sql-set-session-authorization.html\" title=\"SET SESSION AUTHORIZATION\"\u003e\u003ccode class=\"command\"\u003eSET SESSION AUTHORIZATION\u003c/code\u003e\u003c/a\u003e相近，但其中涉及的权限检查完全不同。此外，\u003ccode class=\"command\"\u003eSET SESSION AUTHORIZATION\u003c/code\u003e会决定后续 \u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e命令允许使用哪些角色，而通过 \u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e更改角色并不会改变后续 \u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e允许使用的角色集合。\u003c/p\u003e\u003cp\u003e\u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e不会处理角色的 \u003ca href=\"/docs/18/sql-alterrole.html\" title=\"ALTER ROLE\"\u003e\u003ccode class=\"command\"\u003eALTER ROLE\u003c/code\u003e\u003c/a\u003e设置所指定的会话变量；这只会在登录期间发生。\u003c/p\u003e\u003cp\u003e\u003ccode class=\"command\"\u003eSET ROLE\u003c/code\u003e不能在 \u003ccode class=\"literal\"\u003eSECURITY DEFINER\u003c/code\u003e函数中使用。\u003c/p\u003e","key":"notes","title":"注解"},{"html":"\u003cpre class=\"programlisting\"\u003eSELECT SESSION_USER, CURRENT_USER;\n\n session_user | current_user\n--------------+--------------\n peter        | peter\n\nSET ROLE 'paul';\n\nSELECT SESSION_USER, CURRENT_USER;\n\n session_user | current_user\n--------------+--------------\n peter        | paul\n\u003c/pre\u003e","key":"examples","title":"示例"},{"html":"\u003cp\u003e\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e允许使用标识符语法（\u003ccode class=\"literal\"\u003e\"\u003cem class=\"replaceable\"\u003e\u003ccode\u003erolename\u003c/code\u003e\u003c/em\u003e\"\u003c/code\u003e），而 SQL 标准要求将角色名写成字符串字面量。SQL 不允许在事务中执行这个命令；\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e不施加这一限制，因为没有理由这样做。\u003ccode class=\"literal\"\u003eSESSION\u003c/code\u003e和\u003ccode class=\"literal\"\u003eLOCAL\u003c/code\u003e修饰符，以及 \u003ccode class=\"literal\"\u003eRESET\u003c/code\u003e语法，都是\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e扩展。\u003c/p\u003e","key":"compatibility","title":"兼容性"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/set-session-authorization/?v=18\" title=\"SET SESSION AUTHORIZATION\"\u003e\u003cspan class=\"refentrytitle\"\u003eSET SESSION AUTHORIZATION\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"另见"}],"sections_same_as":"","synopsis_html":"SET [ SESSION | LOCAL ] ROLE \u003cem class=\"replaceable\"\u003e\u003ccode\u003erole_name\u003c/code\u003e\u003c/em\u003e\nSET [ SESSION | LOCAL ] ROLE NONE\nRESET ROLE","synopsis_text":"SET [ SESSION | LOCAL ] ROLE role_name\nSET [ SESSION | LOCAL ] ROLE NONE\nRESET ROLE"}},"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":null,"Spellings":null,"SQLState":null,"Evidence":null}
