REVOKE Strips Table Privileges

REVOKE strips granted privileges while the role itself survives; has_table_privilege verifies exactly which rights remain after each revoke.

SqlSecurity Boundaries

Code

snippet
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

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.