PostgreSQL error code
PostgreSQL error 42501
42501 is the SQLSTATE PostgreSQL reports for insufficient privilege, in class 42, Syntax Error or Access Rule Violation.
| SQLSTATE | 42501 |
|---|---|
| Condition name | insufficient_privilege |
| Class | 42 — Syntax Error or Access Rule Violation |
Reproduce it, then fix it
The reporting role can see the schema but has no SELECT on the table. Grant the privileges it needs, and nothing more. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.
CREATE ROLE reporting; GRANT USAGE ON SCHEMA demo TO reporting; SET LOCAL ROLE reporting; SELECT email FROM customers;
CREATE ROLE reporting; GRANT USAGE ON SCHEMA demo TO reporting; GRANT SELECT ON customers TO reporting; SET LOCAL ROLE reporting; SELECT email FROM customers;