Re: getting all groups where a user belongs to - Mailing list pgsql-general

From Tom Lane
Subject Re: getting all groups where a user belongs to
Date
Msg-id 14261.1252277776@sss.pgh.pa.us
Whole thread Raw
In response to getting all groups where a user belongs to  (Keresztury Balázs <balazs@gaslightmusic.hu>)
List pgsql-general
=?iso-8859-2?Q?Keresztury_Bal=E1zs?= <balazs@gaslightmusic.hu> writes:
> For example: there is a Service user, called Joe, who belongs to the group
> called SER. There is an other one, Kim, who's an administrator (ADM), which
> inherits rights from both SER and CEO. My problem is that I need a query,
> which returns _all_ the group names which Kim belongs to.
> I already find a solution to get the direct parents of a role, but I'd like
> to have all of them to use it for access control.

You could do something like

select rolname from pg_roles where pg_has_role('Kim', rolname, 'USAGE');

but this isn't going to be terribly efficient if you do it over and
over.  You should probably think twice about whether you really need
that data in explicit form on the client side.

            regards, tom lane

pgsql-general by date:

Previous
From: Johan Nel
Date:
Subject: Re: getting all groups where a user belongs to
Next
From: Tom Lane
Date:
Subject: Re: More Snow Leopard problems...