BigQuery · Utility function
BigQuery SESSION_USER
SESSION_USER() returns the email address of the user or service account running the query, or a principal identifier for third-party identities. Use it for audit columns, row access policies and per-user views. BigQuery has no CURRENT_USER; this is the equivalent.
SESSION_USER takes no arguments and returns a STRING. For Google accounts and service accounts that is the email address; for third-party (federated) identities it is the principal identifier. It identifies whoever actually runs the job, so a dashboard, scheduled query or pipeline that runs as a service account sees the service account's email, not the person looking at the result.
Common uses are audit columns with created_by STRING DEFAULT SESSION_USER(), row access policies with FILTER USING (email = SESSION_USER()), and views that show each user only their own rows. CURRENT_USER and USER don't exist in BigQuery and fail with Function not found.
Because the value depends on who runs the query, BigQuery doesn't serve queries that call SESSION_USER from the query cache. A view that filters on SESSION_USER only protects data if users can't query the underlying table directly; share it as an authorized view, or use a row access policy, which applies to the table itself.
Syntax
SESSION_USER()Return value
STRING: the email address of the user or service account running the query, or the principal identifier of a third-party identity.
Examples
Who is running this query?
Returns your own email in the console, or the service account's email when a scheduled query or an application runs it.
SELECT SESSION_USER() AS current_user_email;Audit columns filled by defaults
The INSERT names only amount and reason; BigQuery fills in the ID, the author and the time.
CREATE TABLE `project.finance.manual_adjustments` (
adjustment_id STRING DEFAULT GENERATE_UUID(),
amount NUMERIC,
reason STRING,
created_by STRING DEFAULT SESSION_USER(),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
INSERT INTO `project.finance.manual_adjustments` (amount, reason)
VALUES (NUMERIC '-150.00', 'Duplicate charge refund');Row-level security per account owner
Members of the domain see only the accounts they own. The filter applies to every query on the table, including from BI tools that run as the user.
CREATE ROW ACCESS POLICY own_accounts_only
ON `project.crm.accounts`
GRANT TO ('domain:example.com')
FILTER USING (account_owner_email = SESSION_USER());Your most expensive jobs this week
The JOBS view needs permission to list all jobs in the project. INFORMATION_SCHEMA.JOBS_BY_USER returns only your own jobs without the user filter.
SELECT
job_id,
creation_time,
total_bytes_billed
FROM `region-us`.INFORMATION_SCHEMA.JOBS
WHERE creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)
AND user_email = SESSION_USER()
ORDER BY total_bytes_billed DESC
LIMIT 10;Common mistakes
- Expecting the end user's email behind a BI tool or application. If the tool queries with a service account, SESSION_USER returns that service account.
- Comparing emails with different letter case. Normalize both sides with LOWER() if stored emails may contain uppercase letters.
- Relying on a SESSION_USER filter in a view while users can still read the base table. Share the view as an authorized view, or put a row access policy on the table.
- Calling CURRENT_USER() or USER(). Neither exists in BigQuery; use SESSION_USER().
Cost and performance
- Queries that call SESSION_USER() aren't served from the query cache, so on-demand pricing bills every run.
- INFORMATION_SCHEMA.JOBS is partitioned by creation_time and clustered by user_email, so always filter on creation_time when looking up your own jobs.
FAQ
How do I get the current user in BigQuery?
Run SELECT SESSION_USER(). It returns the email of the account running the query; there is no CURRENT_USER function.
What does SESSION_USER return for a service account?
The service account's email address, for example the account a scheduled query, Airflow connection or BI tool uses to run queries.
Can I use SESSION_USER as a default column value?
Yes. created_by STRING DEFAULT SESSION_USER() records who inserted each row when the INSERT doesn't set the column.
Related
More hash and utility functions
All BigQuery hash and utility functions · All functions · BigQuery error messages
