CURRENT_USER is a zero-argument scalar function defined in the SQL standard that exposes the name of the user currently authenticated to the database. The value is evaluated at statement start and remains constant for the duration of that statement. It reflects the effective user after privilege escalation mechanisms such as SET ROLE in PostgreSQL and Oracle. Because it is context sensitive, it cannot be indexed and is resolved at runtime. CURRENT_USER is often used for auditing, row-level security, and conditional logic. In some databases (e.g., MySQL), the parentheses form CURRENT_USER() is also accepted, but the keyword alone is sufficient and preferred for portability.
SESSION_USER, CURRENT_ROLE, SYSTEM_USER, USER, CURRENT_SCHEMA, CURRENT_CATALOG
SQL-92
CURRENT_USER reflects the active user after privilege changes such as SET ROLE, while SESSION_USER always shows who originally connected.
Yes, if you run SET ROLE or EXECUTE AS inside the same transaction, CURRENT_USER will return the new effective user in subsequent statements. The value is fixed only for the individual statement, not the whole transaction.
Yes. MySQL supports both CURRENT_USER and CURRENT_USER(). The function returns 'user_name@host' rather than just the user name.
Create a policy or view that filters rows where owner = CURRENT_USER. The database engine will automatically substitute the current session's user every time the query runs.