> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.firebolt.io/feedback

```json
{
  "path": "/reference-sql/functions-reference/session/session-user",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

> Reference material for SESSION_USER function

# SESSION_USER

export const QueryWindow = ({content}) => {
  const {sql, result} = content;
  const [inited, setInited] = useState(false);
  const buttonRef = useRef(null);
  useEffect(() => {
    if (!inited && buttonRef.current) {
      runQuery(buttonRef.current, true);
      setInited(true);
    }
  }, []);
  return <div className="query-window">
      <div className="query-toolbar">
        <button className="run-button" onClick={ev => runQuery(ev.target)} ref={buttonRef}>Run Query</button>
        <span className="window-title">Interactive SQL Playground 🔥</span>
      </div>
      <div className="query-content">
        <pre><code className="firebolt-sql language-sql" contentEditable="true" spellCheck="false" data-original-query={sql}>{sql}</code></pre>
        <script type="application/json" className="fallback-result" style={{
    display: "none"
  }}>{JSON.stringify(result)}</script>
        <div className="server-unavailable-banner query-window-hidden">
          The Firebolt playground server is currently unavailable. Using precomputed query results.
        </div>
        <div className="query-results"></div>
      </div>
    </div>;
};

Returns the name of the user running the current query.

## Syntax

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SESSION_USER()
```

## Return Types

`TEXT`

## Examples

<QueryWindow
  content={{
"sql": "SELECT SESSION_USER() as user;",
"result": {
"data": [
  [
    "demoproxy"
  ]
],
"meta": [
  {
    "name": "user",
    "type": "text"
  }
],
"query": {
  "query_id": "7dd2af0d-a015-40d0-aaec-7babb51baf94",
  "query_label": null,
  "request_id": "f7796653-5e3a-4a70-ad7a-2c07c78491be"
},
"rows": 1,
"statistics": {
  "bytes_read": 1,
  "elapsed": 0.006267,
  "rows_read": 1,
  "scanned_bytes_cache": 0,
  "scanned_bytes_storage": 0,
  "time_before_execution": 0.00027004,
  "time_to_execute": 8.673e-05
}
}
}}
/>

The following code example shows the effective privileges of the roles directly assigned to the user running the query:

<QueryWindow
  content={{
"sql": "SELECT\nAR.grantee,\n  AR.role_name,\n  OP.privilege_type,\n  OP.object_type,\n  OP.object_name\nFROM information_schema.applicable_roles AS AR\nJOIN information_schema.object_privileges AS OP\nON (AR.role_name = OP.grantee)\nWHERE\n  AR.grantee = session_user();\n",
"result": {
"data": [
  [
    "demoproxy",
    "proxy_role",
    "SELECT",
    "table",
    "usaccidentdata"
  ],
  [
    "demoproxy",
    "proxy_role",
    "SELECT",
    "table",
    "tournaments"
  ],
  [
    "demoproxy",
    "proxy_role",
    "SELECT",
    "table",
    "t"
  ],
  [
    "demoproxy",
    "proxy_role",
    "SELECT",
    "table",
    "rankings"
  ],
  [
    "demoproxy",
    "proxy_role",
    "SELECT",
    "table",
    "playstats"
  ],
  [
    "demoproxy",
    "proxy_role",
    "SELECT",
    "table",
    "players"
  ],
  [
    "demoproxy",
    "proxy_role",
    "SELECT",
    "table",
    "levels"
  ],
  [
    "demoproxy",
    "proxy_role",
    "SELECT",
    "table",
    "games"
  ],
  [
    "demoproxy",
    "proxy_role",
    "USAGE",
    "schema",
    "public"
  ]
],
"meta": [
  {
    "name": "grantee",
    "type": "text"
  },
  {
    "name": "role_name",
    "type": "text"
  },
  {
    "name": "privilege_type",
    "type": "text"
  },
  {
    "name": "object_type",
    "type": "text"
  },
  {
    "name": "object_name",
    "type": "text"
  }
],
"query": {
  "query_id": "8c7d71d8-7b25-4710-a04e-1e5cfa68fd05",
  "query_label": null,
  "request_id": "331ec51f-7319-48dc-9d5f-2aa565236621"
},
"rows": 9,
"rows_before_limit_at_least": 9,
"statistics": {
  "bytes_read": 1290,
  "elapsed": 0.030399,
  "rows_read": 10,
  "scanned_bytes_cache": 0,
  "scanned_bytes_storage": 0,
  "time_before_execution": 0.000821302,
  "time_to_execute": 0.019480719
}
}
}}
/>

**Example**

Dynamic security through a view which uses `session_user()`.

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
-- 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      | ... |
