]> begriffs open source - ai-pg/blob - full-docs/txt/sql-set-session-authorization.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / sql-set-session-authorization.txt
1
2 SET SESSION AUTHORIZATION
3
4    SET SESSION AUTHORIZATION — set the session user identifier and the
5    current user identifier of the current session
6
7 Synopsis
8
9 SET [ SESSION | LOCAL ] SESSION AUTHORIZATION user_name
10 SET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT
11 RESET SESSION AUTHORIZATION
12
13 Description
14
15    This command sets the session user identifier and the current user
16    identifier of the current SQL session to be user_name. The user name
17    can be written as either an identifier or a string literal. Using this
18    command, it is possible, for example, to temporarily become an
19    unprivileged user and later switch back to being a superuser.
20
21    The session user identifier is initially set to be the (possibly
22    authenticated) user name provided by the client. The current user
23    identifier is normally equal to the session user identifier, but might
24    change temporarily in the context of SECURITY DEFINER functions and
25    similar mechanisms; it can also be changed by SET ROLE. The current
26    user identifier is relevant for permission checking.
27
28    The session user identifier can be changed only if the initial session
29    user (the authenticated user) has the superuser privilege. Otherwise,
30    the command is accepted only if it specifies the authenticated user
31    name.
32
33    The SESSION and LOCAL modifiers act the same as for the regular SET
34    command.
35
36    The DEFAULT and RESET forms reset the session and current user
37    identifiers to be the originally authenticated user name. These forms
38    can be executed by any user.
39
40 Notes
41
42    SET SESSION AUTHORIZATION cannot be used within a SECURITY DEFINER
43    function.
44
45 Examples
46
47 SELECT SESSION_USER, CURRENT_USER;
48
49  session_user | current_user
50 --------------+--------------
51  peter        | peter
52
53 SET SESSION AUTHORIZATION 'paul';
54
55 SELECT SESSION_USER, CURRENT_USER;
56
57  session_user | current_user
58 --------------+--------------
59  paul         | paul
60
61 Compatibility
62
63    The SQL standard allows some other expressions to appear in place of
64    the literal user_name, but these options are not important in practice.
65    PostgreSQL allows identifier syntax ("username"), which SQL does not.
66    SQL does not allow this command during a transaction; PostgreSQL does
67    not make this restriction because there is no reason to. The SESSION
68    and LOCAL modifiers are a PostgreSQL extension, as is the RESET syntax.
69
70    The privileges necessary to execute this command are left
71    implementation-defined by the standard.
72
73 See Also
74
75    SET ROLE