CURRENT_USER() returns the name of the role that is executing the current Snowflake session.
CURRENT_USER() returns the name of the role currently authenticated in the Snowflake session. This is useful for auditing, row-level security, and conditional logic that depends on the executing user.
Call it like any scalar function: SELECT CURRENT_USER(); You can also alias or combine it with other columns to capture context alongside business data.
Syntax is straightforward: CURRENT_USER(); It has no parameters, but Snowflake allows optional parentheses. Use it alone or in larger statements.
```sqlSELECT CURRENT_USER() AS running_user, order_date AS day, SUM(total_amount) AS daily_salesFROM OrdersGROUP BY order_date;```
1) Auditing query logs to see who ran which statements. 2) Adding columns to staging tables that record the loader’s role. 3) Implementing row-level policies that filter rows based on the executing user.
Always CAST the return value explicitly when concatenating with strings. Store it in VARCHAR columns sized to at least 256 characters to handle long role names. Avoid using CURRENT_USER() inside views that should be cached globally.
Mixing CURRENT_USER() with SESSION_USER() – SESSION_USER() is Snowflake-specific and may differ after role changes. Rely on CURRENT_USER() for real-time identity.
Forgetting parentheses – Although optional, adding () keeps code style consistent and prevents parser confusion with identifiers.
Use `USE ROLE analyst;` then run `SELECT CURRENT_USER();` to see the change. Role changes are session-level and immediately affect the function’s output.
CURRENT_USER() is metadata only; it has negligible execution cost even in large joins. Use it freely in SELECT lists without worrying about query plans.
No. CURRENT_USER() returns the role name executing the session, while CURRENT_ROLE() returns the role currently in use, which may differ after a role change.
No. It is a metadata function accessible to all roles. It never exposes data from other accounts.