REVOKE Strips Table Privileges
REVOKE strips granted privileges while the role itself survives; has_table_privilege verifies exactly which rights remain after each revoke.
Code
CREATE ROLE app_reader;
CREATE TABLE audit_log (id integer, note text);
INSERT INTO audit_log VALUES (1, 'boot');
-- grant read and write: the two privileges take effect independently
GRANT SELECT, UPDATE ON audit_log TO app_reader;
SELECT has_table_privilege('app_reader', 'audit_log', 'SELECT') AS can_read,
has_table_privilege('app_reader', 'audit_log', 'UPDATE') AS can_write;
-- REVOKE strips the named privilege; ALL clears everything, the role itself survives
REVOKE UPDATE ON audit_log FROM app_reader;
SELECT has_table_privilege('app_reader', 'audit_log', 'UPDATE') AS after_revoke;
REVOKE ALL ON audit_log FROM app_reader;
SELECT has_table_privilege('app_reader', 'audit_log', 'SELECT') AS after_revoke_all,
has_table_privilege('app_reader', 'audit_log', 'UPDATE') AS update_also_gone;What the demo revokes
GRANT SELECT, UPDATE gives app_reader two independent privileges, and the first has_table_privilege pair prints true for both. REVOKE UPDATE removes exactly that one: the after_revoke probe flips to false while SELECT still stands.
REVOKE ALL then clears the remaining set, and both columns of the final probe print false. The role itself survives every revoke; only the privilege rows disappear, which is why re-granting later works without recreating anything.
Caveats and details
- Privileges are checked one by one; ALL is a batch clear, not a special grant.
- The table data stays; revocation changes access, not contents.
Interactive Tools for This Topic
PostgreSQL EXPLAIN AnalyzerAnalyze PostgreSQL EXPLAIN ANALYZE text or FORMAT JSON plans locally to flag Seq Scans, slow nodes, row misestimates, disk sorts, and index hints.SQL DDL to TypeScript ConverterConvert SQL CREATE TABLE DDL statements into strict TypeScript interfaces with nullable, array, enum, JSONB, and Date or ISO string column mappings.Argon2id Hash InfoEstimate Argon2id password-hash latency and memory usage, and check your parameters against OWASP 2024 minimum and recommended settings.bcrypt Cost EstimatorEstimate bcrypt cost factor latency and brute-force resistance, and get a recommended cost for your target hash time and attacker throughput.
FAQ
- Does REVOKE ALL drop the role?
- No; it clears the privileges only. app_reader continues to exist, which is why the final has_table_privilege probes return false rather than erroring.
Report a problem with this exampleOpens a pre-filled issue on GitHub.