Pretty cut and dry, I am just a total noob. Is there a way to make a given role inherit from another?
1 Answer
CREATE ROLE doe LOGIN INHERIT;
CREATE ROLE sales NOINHERIT;
CREATE ROLE marketing NOINHERIT;
GRANT sales to doe;
GRANT marketing to sales;
If you connect to PostgreSQL as doe, you will have privileges of doe plus privileges granted to sales, because doe user role has INHERIT attribute. However, you do not have privileges of marketing because the NOINHERIT attribute is defined for the sales user role.
Note:
The role attributes LOGIN, SUPERUSER, CREATEDB, and CREATEROLE can be thought of as special privileges, but they are never inherited as ordinary privileges on database objects are.
-
4The purpose of
NOINHERIT
is that you still have the right toSET ROLE sales;
and then act as thesales
role, but you must do so explicitly. So it's good for granting rights that should only be exersized intentionally, kind of like "sudo". Mar 15, 2014 at 0:55 -
1I could not imagine a real life use case for this. If we do not want a role inherit from another role, then why do we grant?– edibJun 1, 2018 at 11:07