7

Pretty cut and dry, I am just a total noob. Is there a way to make a given role inherit from another?

1 Answer 1

12
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.

2
  • 4
    The purpose of NOINHERIT is that you still have the right to SET ROLE sales; and then act as the sales 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
  • 1
    I 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?
    – edib
    Jun 1, 2018 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.