Column-Level Security

Grant or revoke SELECT privileges to columns in a table. These privileges can be managed separately of table-level privileges, allowing for SELECT operations on a subset of columns.

Synopsis

GRANT SELECT (<column1>,<column2>,...<columnN>) ON TABLE <table> TO <entity>;

REVOKE SELECT (<column1>,<column2>,...<columnN>) ON TABLE <table> FROM <entity>;

The <entity> referred to above can either be a role or user.

The above GRANT and REVOKE commands can be compounded with other privileges. For example

GRANT SELECT (salary), UPDATE ON TABLE employees TO test_user;

grants the SELECT column privilege on the table employees to test_user as well as UPDATE privileges.

Examples

CREATE USER test_user (PASSWORD='test');
CREATE TABLE employees (id INT, salary BIGINT);
  1. Grant SELECT on a single column.

  1. Revoke SELECT on a single column.

The following also revokes column privileges.

  1. Grant SELECT on multiple columns.

  1. Revoke SELECT on multiple columns.

  1. Granting SELECT on any column allows access to metadata.

  1. Allowing SELECT privilege on a subset of columns will enable certain queries and disable others.

  1. Any subqueries used within a query will enforce similar column-level security.

  1. Table-level privileges supersede column-level privileges. Revoking column-privilege will not affect table-level privileges.

Last updated