SET ROLE <refpurpose>set the current user identifier of the current session</refpurpose> — 現在のセッションにおける現在のユーザ識別子を設定する
SET [ SESSION | LOCAL ] ROLE role_name
SET [ SESSION | LOCAL ] ROLE NONE
RESET ROLE
This command sets the current user
identifier of the current SQL session to be <replaceable
class="parameter">role_name</replaceable>. The role name can be
written as either an identifier or a string literal.
After <command>SET ROLE</command>, permissions checking for SQL commands
is carried out as though the named role were the one that had logged
in originally. Note that <command>SET ROLE</command> and
<command>SET SESSION AUTHORIZATION</command> are exceptions; permissions
checks for those continue to use the current session user and the initial
session user (the <firstterm>authenticated user</firstterm>), respectively.
このコマンドは現在のSQLセッションにおける現在のユーザ識別子をrole_nameに設定します。
ロール名は識別子あるいは文字列リテラルのどちらを使用しても記述することができます。
SET ROLEの後、SQLコマンドに対する権限検査は、指定されたロールで普通にログインした場合と同様に行われます。
SET ROLEとSET SESSION AUTHORIZATIONは例外であることに注意してください。これらに対する権限検査は、それぞれ現在のセッションユーザと初期セッションユーザ(認証されたユーザ)を使い続けます。
The current session user must have the <literal>SET</literal> option for the
specified <replaceable class="parameter">role_name</replaceable>, either
directly or indirectly via a chain of memberships with the
<literal>SET</literal> option.
(If the session user is a superuser, any role can be selected.)
現在のセッションユーザは、直接的にまたはSETオプションを使用したメンバシップの連鎖を介して間接的に、指定するrole_nameに対してSETオプションを持つことが必要です。
(セッションユーザがスーパーユーザであった場合、任意のロールを選択することができます。)
The <literal>SESSION</literal> and <literal>LOCAL</literal> modifiers act the same
as for the regular <link linkend="sql-set"><command>SET</command></link>
command.
SESSIONおよびLOCAL修飾子は通常のSETコマンドと同様に動作します。
<literal>SET ROLE NONE</literal> sets the current user identifier to the
current session user identifier, as returned by
<function>session_user</function>. <literal>RESET ROLE</literal> sets the
current user identifier to the connection-time setting specified by the
<link linkend="libpq-connect-options">command-line options</link>,
<link linkend="sql-alterrole"><command>ALTER ROLE</command></link>, or
<link linkend="sql-alterdatabase"><command>ALTER DATABASE</command></link>,
if any such settings exist. Otherwise, <literal>RESET ROLE</literal> sets
the current user identifier to the current session user identifier. These
forms can be executed by any user.
SET ROLE NONEは現在のユーザ識別子をsession_userにより返される現在のセッションユーザ識別子に設定します。
RESET ROLEは現在のユーザ識別子を、設定が存在するのならコマンドラインオプション、ALTER ROLEやALTER DATABASEで指定される接続時の設定にします。
そうでなければ、RESET ROLEは現在のユーザ識別子を現在のセッションユーザ識別子に設定します。
この構文はすべてのユーザが実行できます。
Using this command, it is possible to either add privileges or restrict
one's privileges. If the session user role has been granted memberships
<literal>WITH INHERIT TRUE</literal>, it automatically has all the
privileges of every such role. In this case, <command>SET ROLE</command>
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 <literal>WITH INHERIT FALSE</literal>, the
privileges of the granted roles can't be accessed by default. However, if
the role was granted <literal>WITH SET TRUE</literal>, the
session user can use <command>SET ROLE</command> 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 <literal>WITH INHERIT
FALSE, SET FALSE</literal> then the privileges of that role cannot be
exercised either with or without <literal>SET ROLE</literal>.
このコマンドを使用して、権限を追加することも制限することもできます。
セッションユーザのロールにWITH INHERIT TRUEメンバ資格が付与されている場合、そのロールのすべての権限が自動的に付与されます。
この場合、SET ROLEによって、対象のロールが直接所有している権限と継承している権限を除くすべての権限が事実上削除されます。
一方、セッションユーザのロールにWITH INHERIT FALSEメンバ資格が付与されている場合、デフォルトでは付与されたロールの権限にアクセスできません。
ただし、ロールにWITH SET TRUEが付与されている場合、セッションユーザはSET ROLEを使用して、セッションユーザに直接権限を付与する権限を削除し、代わりに指定されたロールに対して使用可能な権限を取得できます。
ロールにWITH INHERIT FALSE, SET FALSEが付与されている場合、SET ROLEの有無にかかわらず、その権限を行使できません。
<command>SET ROLE</command> has effects comparable to
<link linkend="sql-set-session-authorization"><command>SET SESSION AUTHORIZATION</command></link>, but the privilege
checks involved are quite different. Also,
<command>SET SESSION AUTHORIZATION</command> determines which roles are
allowable for later <command>SET ROLE</command> commands, whereas changing
roles with <command>SET ROLE</command> does not change the set of roles
allowed to a later <command>SET ROLE</command>.
SET ROLEの影響はSET SESSION AUTHORIZATIONと似ていますが、行われる権限検査はかなり異なります。
また、SET SESSION AUTHORIZATIONは、それ以降に実行するSET ROLEコマンドでどのロールに変更できるかを決定しますが、SET ROLEを使用してロールを変更した場合、それ以降に実行するSET ROLEコマンドで変更可能なロール群は変更されません。
<command>SET ROLE</command> does not process session variables as specified by
the role's <link linkend="sql-alterrole"><command>ALTER ROLE</command></link> settings; this only happens during
login.
SET ROLEはロールのALTER ROLE設定で指定されたセッション変数を処理しません。
これはログイン時のみ適用されます。
<command>SET ROLE</command> cannot be used within a
<literal>SECURITY DEFINER</literal> function.
SET ROLEをSECURITY DEFINER関数内で使用することはできません。
SELECT SESSION_USER, CURRENT_USER; session_user | current_user --------------+-------------- peter | peter SET ROLE 'paul'; SELECT SESSION_USER, CURRENT_USER; session_user | current_user --------------+-------------- peter | paul
<productname>PostgreSQL</productname>
allows identifier syntax (<literal>"<replaceable>rolename</replaceable>"</literal>), while
the SQL standard requires the role name to be written as a string
literal. SQL does not allow this command during a transaction;
<productname>PostgreSQL</productname> does not make this
restriction because there is no reason to.
The <literal>SESSION</literal> and <literal>LOCAL</literal> modifiers are a
<productname>PostgreSQL</productname> extension, as is the
<literal>RESET</literal> syntax.
PostgreSQLでは、識別子構文(")を使用できます。
しかし、標準SQLではロール名を文字列リテラルとして記述しなければなりません。
SQLでは、トランザクション内でこのコマンドを実行することを許可していません。
PostgreSQLでは、このように制限する理由がありませんので、この制限はありません。
rolename"SESSION、LOCAL修飾子、および、RESET構文はPostgreSQLの拡張です。