How to Use CURRENT_USER in PostgreSQL

Galaxy Glossary

How do I use CURRENT_USER in PostgreSQL?

CURRENT_USER returns the name of the role that initiated the current session.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Description

Table of Contents

PostgreSQL CURRENT_USER Guide

Use CURRENT_USER to quickly identify the role executing your SQL statements, enforce row-level security, or audit activity without extra joins.

What does CURRENT_USER return?

CURRENT_USER outputs the sessions authorization identifierthe role originally used to connect, even after SET ROLE.

How do I call CURRENT_USER?

Call it like any SQL function or use it in expressions, WHERE clauses, and DDL statements. No parentheses needed.

Example: show current login

SELECT CURRENT_USER;

When should I prefer CURRENT_USER over SESSION_USER or 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).

Can I use CURRENT_USER in policies?

Yes. RowLevel Security (RLS) policies commonly reference CURRENT_USER to restrict rows to their owners.

CREATE POLICY owner_only
USING (owner = CURRENT_USER);

Does CURRENT_USER accept parameters?

No parametersit is a SQL keyword that returns text.

Best practices

2 Store usernames in lower case to avoid casesensitive comparisons.
2 Combine with COALESCE for robust auditing tables.

Full syntax

CURRENT_USER | USER -- both keywords are equivalent

Why How to Use CURRENT_USER in PostgreSQL is important

How to Use CURRENT_USER in PostgreSQL Example Usage


SELECT CURRENT_USER AS connected_role;

How to Use CURRENT_USER in PostgreSQL Syntax


CURRENT_USER | USER

Common Mistakes

Frequently Asked Questions (FAQs)

Is CURRENT_USER the same as USER?

Yes, USER is a SQL standard alias for CURRENT_USER in PostgreSQL.

Will CURRENT_USER change after SET ROLE?

No. CURRENT_USER keeps the session’s original authorization identifier. Use CURRENT_ROLE to see the active role.

What data type does CURRENT_USER return?

It returns type name (text) representing the role identifier.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.