currentUser() returns the ClickHouse username executing the query.
currentUser() outputs the exact ClickHouse username that is running the statement. The value is pulled from the current session, making it ideal for auditing and security checks.
Place currentUser() anywhere a scalar expression is allowed. Always include empty parentheses; the function takes no arguments.
SELECT currentUser() AS executing_user;
Use it in INSERT … SELECT statements to log who loaded data, in WHERE clauses for row-level security, or in SELECT lists for real-time monitoring dashboards.
Capture the username whenever Orders or OrderItems are bulk-inserted to trace responsibility.
Filter Orders so analysts only see rows they own by comparing order_creator to currentUser().
Combine currentUser() with initialUser() to distinguish proxied traffic. Store the value in a low-cardinality column when writing logs for efficient compression.
No special privilege is needed; any authenticated user can call currentUser().
Yes, but remember the function is evaluated at insert time, not at view query time. Ensure this matches your auditing intent.
CREATE TABLE Orders_Audit AS
SELECT *,
currentUser() AS inserted_by,
now() AS inserted_at
FROM Orders;
The view above keeps a historical copy of every order plus who inserted it.
No. currentUser(), CURRENTUSER(), and CurrentUser() all work, but lowercase is conventional.
Yes. The function returns the username provided in the HTTP header or URL parameters.
Not directly. Instead, restrict the user’s ability to query sensitive tables that expose the function’s result.