PostgreSQL 0LP01: invalid grant operation
A GRANT or REVOKE asked for something PostgreSQL doesn't allow, such as WITH GRANT OPTION to PUBLIC or granting a role to itself.
- SQLSTATE
0LP01- Name
invalid_grant_operation- Category
- Invalid Grantor
What it means
0LP01 (invalid_grant_operation) is raised when the shape of a GRANT or REVOKE is invalid, not when you lack the privilege (that is 42501). The common messages are grant options can only be granted to roles (for WITH GRANT OPTION to PUBLIC) and errors about circular role membership, such as granting a role to itself or to a role that is already a member of it.
Common causes
GRANT ... TO PUBLIC WITH GRANT OPTION.- Granting a role to itself, or creating a membership loop (
GRANT a TO bwhenbis already a member ofa). - Scripts generated for another database's privilege model.
How to fix it
-
Grant with grant option to a specific role instead of
PUBLIC.GRANT SELECT ON orders TO reporting WITH GRANT OPTION;
-
Check existing role memberships before adding one, to avoid loops.
SELECT r.rolname AS role, m.rolname AS member FROM pg_auth_members am JOIN pg_roles r ON r.oid = am.roleid JOIN pg_roles m ON m.oid = am.member;
Reproduce it safely
CREATE TEMP TABLE t (id int); GRANT SELECT ON t TO PUBLIC WITH GRANT OPTION; -- ERROR: grant options can only be granted to roles
Related errors
The code and message text are from the PostgreSQL documentation, Appendix A: PostgreSQL Error Codes. Browse the full PostgreSQL error list or search every database error.
Work on PostgreSQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for PostgreSQL and the other databases you use.