Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revoke particular columns in postgresql

I've tried using the documentation here but doesn't seem to help. If you can please give me an example.

revoke select (column1, column2) on table from specific_user

hasn't worked.

Access privileges
 Schema | Name  | Type  |     Access privileges     | Column privileges | Policies 
--------+-------+-------+---------------------------+-------------------+----------
 public | users | table | himanshu=arwdDxt/himanshu+|                   | 
        |       |       | reports_user=r/himanshu   |                   | 
(1 row)
like image 319
tambakoo Avatar asked Dec 24 '22 11:12

tambakoo


1 Answers

The problem is that privileges in SQL are additive, and column privileges and table privileges are different.

Revoking a privilege that you didn't grant before has no effect, and granting SELECT on a table is different from granting SELECT on all columns.

You should revoke the SELECT privilege on the table and grant SELECT on all columns except the one where you want to deny access:

REVOKE SELECT ON "table" FROM specific_user;
GRANT SELECT (<all columns except "column1" and "column2">)
   ON "table" TO specific_user;

Check the result with \z "table".

like image 185
Laurenz Albe Avatar answered Jan 09 '23 06:01

Laurenz Albe