CURRENT_USER returns the name of the role that initiated the current session.
Use CURRENT_USER to quickly identify the role executing your SQL statements, enforce row-level security, or audit activity without extra joins.
CURRENT_USER outputs the sessions authorization identifierthe role originally used to connect, even after SET ROLE.
Call it like any SQL function or use it in expressions, WHERE clauses, and DDL statements. No parentheses needed.
SELECT CURRENT_USER;
Pick CURRENT_USER for security checks because it respects SET SESSION AUTHORIZATION while still reflecting the original role, unlike USER (alias for CURRENT_USER) or SESSION_USER (never changes).
Yes. RowLevel Security (RLS) policies commonly reference CURRENT_USER to restrict rows to their owners.
CREATE POLICY owner_only
USING (owner = CURRENT_USER);
No parametersit is a SQL keyword that returns text.
2 Store usernames in lower case to avoid casesensitive comparisons.
2 Combine with COALESCE for robust auditing tables.
CURRENT_USER | USER -- both keywords are equivalent
Yes, USER is a SQL standard alias for CURRENT_USER in PostgreSQL.
No. CURRENT_USER keeps the session’s original authorization identifier. Use CURRENT_ROLE to see the active role.
It returns type name (text) representing the role identifier.