Query grants for a table in postgres

后端 未结 7 678
栀梦
栀梦 2020-12-22 22:19

How can I query all GRANTS granted to an object in postgres?

For example I have table \"mytable\":

GRANT SELECT, INSERT ON mytable TO user1
GRANT UPD         


        
7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-22 23:03

    If you really want one line per user, you can group by grantee (require PG9+ for string_agg)

    SELECT grantee, string_agg(privilege_type, ', ') AS privileges
    FROM information_schema.role_table_grants 
    WHERE table_name='mytable'   
    GROUP BY grantee;
    

    This should output something like :

     grantee |   privileges   
    ---------+----------------
     user1   | INSERT, SELECT
     user2   | UPDATE
    (2 rows)
    

提交回复
热议问题