Re: check user in group

From: Pavel Stehule <pavel(dot)stehule(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 10:22:41
Message-ID: CAFj8pRB3a-kuiCNvHcwxjRKb7yCQP3_Si034ut-vTrzQRbQpnw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

you can try

create or replace function is_member_of(text, text) returns boolean as $$
select exists(select rolname from pg_catalog.pg_auth_members m JOIN
pg_catalog.pg_roles b ON m.roleid = b.oid where m.member = (select oid
from pg_roles where rolname = $1) and rolname = $2)
$$ language sql ;

postgres=# select is_member_of('pavel','admin');
is_member_of
--------------
t
(1 row)

Regards

Pavel Stehule

2012/12/25 Philipp Kraus <philipp(dot)kraus(at)flashpixx(dot)de>:
> 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
>
> Thanks
>
> Phil
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Philipp Kraus 2012-12-25 11:32:57 dataset user access
Previous Message Philipp Kraus 2012-12-25 09:51:06 check user in group