Re: [HACKERS] Role members - Mailing list pgsql-general

From Jim Nasby
Subject Re: [HACKERS] Role members
Date
Msg-id 9AC2CA53-2BE2-4DB3-8902-C9543097424E@decibel.org
Whole thread Raw
In response to Re: [HACKERS] Role members  (David Fetter <david@fetter.org>)
List pgsql-general
On May 21, 2007, at 8:25 AM, David Fetter wrote:
> On Mon, May 21, 2007 at 02:21:52PM +0400, Akmal Akmalhojaev wrote:
>> For example I have a role ID1 with members ID2 and ID3.
>> Role ID2 has also members ID4 and ID5. It means that roles ID4 and
>> ID5 are
>> members of ID1.
>> The question: Is there any function in PostgreSQL, that finds all the
>> members of role ID1 - even such members, as ID4 and ID5.
>
> Here's a function I've written in SQL:
>
> CREATE OR REPLACE FUNCTION get_roles_under(OID)
> RETURNS SETOF OID
> LANGUAGE sql
> AS $$
> SELECT
>     $1
> UNION
> SELECT
>     member
> FROM
>     pg_catalog.pg_auth_members
> WHERE
>     roleid = $1
> UNION
> SELECT
>     get_roles_over(roleid) AS "roleid"
> FROM
>     pg_catalog.pg_auth_members
> WHERE
>     roleid IN (
>         SELECT
>             member
>         FROM
>             pg_catalog.pg_auth_members
>         WHERE
>             roleid = $1
>     )
> $$;

Should that call to get_roles_over be a call to get_roles_under?
--
Jim Nasby                                            jim@nasby.net
EnterpriseDB      http://enterprisedb.com      512.569.9461 (cell)



pgsql-general by date:

Previous
From: Jim Nasby
Date:
Subject: Re: feature suggestions
Next
From: "Albe Laurenz"
Date:
Subject: Re: hundreds of schema vs hundreds of databases