Skip to main content
Returns the name of the user running the current query.

Syntax

SESSION_USER()

Return Types

TEXT

Examples

SELECT SESSION_USER() as user;
user text
demoproxy

Rows: 1Execution time: 5.75ms

The following code example shows the effective privileges of the roles directly assigned to the user running the query:
SELECT
AR.grantee,
  AR.role_name,
  OP.privilege_type,
  OP.object_type,
  OP.object_name
FROM information_schema.applicable_roles AS AR
JOIN information_schema.object_privileges AS OP
ON (AR.role_name = OP.grantee)
WHERE
  AR.grantee = session_user();

grantee textrole_name textprivilege_type textobject_type textobject_name text
demoproxyproxy_roleSELECTtableusaccidentdata
demoproxyproxy_roleSELECTtabletournaments
demoproxyproxy_roleSELECTtablet
demoproxyproxy_roleSELECTtablerankings
demoproxyproxy_roleSELECTtableplaystats
demoproxyproxy_roleSELECTtableplayers
demoproxyproxy_roleSELECTtablelevels
demoproxyproxy_roleSELECTtablegames
demoproxyproxy_roleUSAGEschemapublic

Rows: 9Execution time: 40.41ms

Example Dynamic security through a view which uses session_user().
-- user bob created view:
create view my_employee_data as select * from employees where user_name = session_user();

-- user alice queries it:
select * from my_employee_data; -- session_user() will be evaluated to 'alice' for this query
Returns
user_name
alice