looking up members of a group

From: Michiel Lange <michiel(at)minas(dot)demon(dot)nl>
To: pgsql-novice(at)postgresql(dot)org
Subject: looking up members of a group
Date: 2003-03-13 07:07:56
Message-ID: 5.1.0.14.0.20030313080139.027a4cf0@192.168.1.3
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi all,

I am looking for a way to determine wether or not a user is a member of a
group...

if I do: SELECT * FROM pg_group;
I get something like this:
groname | grosysid | grolist
----------+----------+-----------------------
users | 103 | {100,102}
admins | 101 | {103,1}
guests | 100 | {101}
customer | 102 | {104,105,106,107,108}

that's pretty ok, and it appears that the members of the group are in an
array... arrays in a database... it's always been a blast to me, always
having trouble working with them, so I don't use arrays often... but here I
must *grin*

Anyway... I want to know if a user 'john' is member of 'admins', to
determine wether or not to show an administrative button on the website. I
was thinking of creating a function in PL/SQL, but I still have not the
hang of that... but it would be nice to do a:
SELECT * FROM is_member(john,admin); where it would return a boolean saying
yes or no...
or
SELECT * FROM is_member(john); where it would return a column with all the
groups john is member of...

maybe someone can help me out?
TIA,
Michiel

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Jules Alberts 2003-03-13 07:35:36 Re: filtering out doubles with SELECT
Previous Message jenner viloria 2003-03-13 06:46:33 client