2 <refentry id=
"SQL-SET-SESSION-AUTHORIZATION">
4 <refentrytitle id=
"sql-set-session-authorization-title">SET SESSION AUTHORIZATION
</refentrytitle>
5 <manvolnum>7</manvolnum>
6 <refmiscinfo>SQL - Language Statements
</refmiscinfo>
10 <refname>SET SESSION AUTHORIZATION
</refname>
11 <refpurpose>set the session user identifier and the current user identifier of the current session
</refpurpose>
14 <indexterm zone=
"sql-set-session-authorization">
15 <primary>SET SESSION AUTHORIZATION
</primary>
20 SET [ SESSION | LOCAL ] SESSION AUTHORIZATION
<replaceable class=
"parameter">username
</replaceable>
21 SET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT
22 RESET SESSION AUTHORIZATION
27 <title>Description
</title>
30 This command sets the session user identifier and the current user
31 identifier of the current SQL session to be
<replaceable
32 class=
"parameter">username
</replaceable>. The user name can be
33 written as either an identifier or a string literal. Using this
34 command, it is possible, for example, to temporarily become an
35 unprivileged user and later switch back to being a superuser.
39 The session user identifier is initially set to be the (possibly
40 authenticated) user name provided by the client. The current user
41 identifier is normally equal to the session user identifier, but
42 might change temporarily in the context of
<literal>SECURITY DEFINER<
/>
43 functions and similar mechanisms; it can also be changed by
44 <xref linkend=
"sql-set-role" endterm=
"sql-set-role-title">.
45 The current user identifier is relevant for permission checking.
49 The session user identifier can be changed only if the initial session
50 user (the
<firstterm>authenticated user
</firstterm>) had the
51 superuser privilege. Otherwise, the command is accepted only if it
52 specifies the authenticated user name.
56 The
<literal>SESSION<
/> and
<literal>LOCAL<
/> modifiers act the same
57 as for the regular
<xref linkend=
"SQL-SET" endterm=
"SQL-SET-title">
62 The
<literal>DEFAULT<
/> and
<literal>RESET<
/> forms reset the session
63 and current user identifiers to be the originally authenticated user
64 name. These forms can be executed by any user.
72 <command>SET SESSION AUTHORIZATION<
/> cannot be used within a
73 <literal>SECURITY DEFINER<
/> function.
78 <title>Examples
</title>
81 SELECT SESSION_USER, CURRENT_USER;
83 session_user | current_user
84 --------------+--------------
87 SET SESSION AUTHORIZATION 'paul';
89 SELECT SESSION_USER, CURRENT_USER;
91 session_user | current_user
92 --------------+--------------
98 <title>Compatibility
</title>
101 The SQL standard allows some other expressions to appear in place
102 of the literal
<replaceable>username
</replaceable>, but these options
103 are not important in practice.
<productname>PostgreSQL
</productname>
104 allows identifier syntax (
<literal>"username"</literal>), which SQL
105 does not. SQL does not allow this command during a transaction;
106 <productname>PostgreSQL
</productname> does not make this
107 restriction because there is no reason to.
108 The
<literal>SESSION<
/> and
<literal>LOCAL<
/> modifiers are a
109 <productname>PostgreSQL
</productname> extension, as is the
110 <literal>RESET<
/> syntax.
114 The privileges necessary to execute this command are left
115 implementation-defined by the standard.
120 <title>See Also
</title>
122 <simplelist type=
"inline">
123 <member><xref linkend=
"sql-set-role" endterm=
"sql-set-role-title"></member>