Re: user/groups query ?

From: John DeSoi <desoi(at)pgedit(dot)com>
To: Zlatko Matić <zlatko(dot)matic1(at)sb(dot)t-com(dot)hr>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: user/groups query ?
Date: 2005-06-20 01:40:49
Message-ID: 6d06539e7f37ab5085077ddd42c2b686@pgedit.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Jun 19, 2005, at 3:56 PM, Zlatko Matić wrote:

>  
> How to make a query that will include information both about user and
> group (or groups) he belongs to ?
> Thanks.

Turning on the ECHO_HIDDEN feature in psql shows how to do this.

\set ECHO_HIDDEN 1
\du user1
********* QUERY **********
SELECT u.usename AS "User name",
u.usesysid AS "User ID",
CASE WHEN u.usesuper AND u.usecreatedb THEN CAST('superuser, create
database' AS pg_catalog.text)
WHEN u.usesuper THEN CAST('superuser' AS pg_catalog.text)
WHEN u.usecreatedb THEN CAST('create database' AS
pg_catalog.text)
ELSE CAST('' AS pg_catalog.text)
END AS "Attributes",
ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid =
ANY(g.grolist)) as "Groups"
FROM pg_catalog.pg_user u
WHERE u.usename ~ '^user1$'
ORDER BY 1;
**************************

List of users
User name | User ID | Attributes | Groups
-----------+---------+------------+--------
user1 | 100 | | {test}
(1 row)

John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andres 2005-06-20 02:08:50 Re: Insert behavior in transaction
Previous Message Lee Harr 2005-06-20 01:19:05 plpgsql constraint checked data fails to restore