Re: select all groups a user belongs to in system tablesl - Mailing list pgsql-general

From frbn
Subject Re: select all groups a user belongs to in system tablesl
Date
Msg-id 3D50C9B7.7060801@efbs-seafrigo.fr
Whole thread Raw
In response to select all groups a user belongs to in system tables  (Uwe Feldtmann <uwe@microshare.com.au>)
List pgsql-general
Uwe Feldtmann a écrit:
 > Hi,
 >
 > I'm new to sql and postgres and I am trying to create a query that will
 > return the list of groups a user belongs to.
 >
 > As the grolist column in pg_group is an array is there a simple way to
 > return the list?
 >
 > I've checked the array documentation and according to that document the
 > pg_group table should be redesigned.
 >
 > Any assistance would be welcome. Thanks in advanced.
 >

create a function in your database(s):

create function "seek_tab" (integer[],integer) returns boolean as '
    declare i int4;
    ufound boolean;
    begin
              i:=1;
              ufound:=false;
              while $1[i]<>0 and not ufound loop
                      if $1[i] = $2 then
                              ufound:=true;
                     end if;
                      i:=i+1;
              end loop;
              return ufound;
    end;
' LANGUAGE 'plpgsql';

------------
and the query to use it is:


select groname from pg_group where rech_tab(grolist,(select usesysid from pg_user where usename='foo'))=true ;


ps: I'm not a pl/pgsql guru :\



pgsql-general by date:

Previous
From: Patrick Nelson
Date:
Subject: Re: Importing blob
Next
From: Jean-Christian Imbeault
Date:
Subject: COPY: how to use "," as a delimeter?