Re: check user in group

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: Philipp Kraus <philipp(dot)kraus(at)flashpixx(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: check user in group
Date: 2012-12-25 16:32:29
Message-ID: 50D9D51D.1070002@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 12/25/2012 01:51 AM, Philipp Kraus wrote:
> Hello,
>
> how can I check if a user is within a group? I use current_user() to get the logged-in user, but I have a group "service" and I need a check if the user is member of the group
>

In recent versions of Postgres user and group have been folded into
roles. The terms still exist, to roughly mean user=role with login,
group=role without login. There are built in functions to work with
roles and privileges. See:

http://www.postgresql.org/docs/9.2/interactive/functions-info.html

Table 9-51. Access Privilege Inquiry Functions
...
pg_has_role(user, role, privilege) boolean does user have privilege for role
pg_has_role(role, privilege) boolean does current user have privilege
for role

There are more available.

> Thanks
>
> Phil
>

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2012-12-25 16:46:43 Re: Problem with the semantics of "select into" in a plpgsql function
Previous Message David Johnston 2012-12-25 16:26:00 Re: Problem with the semantics of "select into" in a plpgsql function