1SET ROLE()                       SQL Commands                       SET ROLE()
2
3
4

NAME

6       SET ROLE - set the current user identifier of the current session
7
8

SYNOPSIS

10       SET [ SESSION | LOCAL ] ROLE rolename
11       SET [ SESSION | LOCAL ] ROLE NONE
12       RESET ROLE
13
14

DESCRIPTION

16       This  command  sets the current user identifier of the current SQL ses‐
17       sion to be rolename. The role name may be written as either an  identi‐
18       fier or a string literal.  After SET ROLE, permissions checking for SQL
19       commands is carried out as though the named role were the one that  had
20       logged in originally.
21
22       The  specified rolename must be a role that the current session user is
23       a member of.  (If the session user is a  superuser,  any  role  can  be
24       selected.)
25
26       The  SESSION  and  LOCAL  modifiers act the same as for the regular SET
27       [set(7)] command.
28
29       The NONE and RESET forms reset the current user identifier  to  be  the
30       current  session  user  identifier.  These forms may be executed by any
31       user.
32

NOTES

34       Using this command, it is possible to either add privileges or restrict
35       one's  privileges. If the session user role has the INHERITS attribute,
36       then it automatically has all the privileges  of  every  role  that  it
37       could  SET  ROLE  to;  in  this case SET ROLE effectively drops all the
38       privileges assigned directly to the session user and to the other roles
39       it  is  a member of, leaving only the privileges available to the named
40       role. On the other hand, if the session user role  has  the  NOINHERITS
41       attribute,  SET ROLE drops the privileges assigned directly to the ses‐
42       sion user and instead acquires the privileges available  to  the  named
43       role.
44
45       In  particular, when a superuser chooses to SET ROLE to a non-superuser
46       role, she loses her superuser privileges.
47
48       SET ROLE has effects comparable to SET SESSION AUTHORIZATION  [set_ses‐
49       sion_authorization(7)],  but  the  privilege  checks involved are quite
50       different. Also, SET SESSION AUTHORIZATION determines which  roles  are
51       allowable  for later SET ROLE commands, whereas changing roles with SET
52       ROLE does not change the set of roles allowed to a later SET ROLE.
53
54       SET ROLE cannot be used within a SECURITY DEFINER function.
55

EXAMPLES

57       SELECT SESSION_USER, CURRENT_USER;
58
59        session_user | current_user
60       --------------+--------------
61        peter        | peter
62
63       SET ROLE 'paul';
64
65       SELECT SESSION_USER, CURRENT_USER;
66
67        session_user | current_user
68       --------------+--------------
69        peter        | paul
70
71

COMPATIBILITY

73       PostgreSQL allows identifier syntax ("rolename"), while the  SQL  stan‐
74       dard requires the role name to be written as a string literal. SQL does
75       not allow this command during a transaction; PostgreSQL does  not  make
76       this  restriction because there is no reason to.  The SESSION and LOCAL
77       modifiers are a PostgreSQL extension, as is the RESET syntax.
78

SEE ALSO

80       SET SESSION AUTHORIZATION [set_session_authorization(7)]
81
82
83
84SQL - Language Statements         2008-06-08                        SET ROLE()
Impressum