Re: user/groups query ?

From: Zlatko Matić <zlatko(dot)matic1(at)sb(dot)t-com(dot)hr>
To: "John DeSoi" <desoi(at)pgedit(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: user/groups query ?
Date: 2005-06-20 19:48:51
Message-ID: 000701c575e5$161c6f50$54301dc3@zlatkovyfkpgz6
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thank you very much !

----- Original Message -----
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>
Sent: Monday, June 20, 2005 3:40 AM
Subject: Re: [GENERAL] user/groups query ?

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

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Karl O. Pinc 2005-06-20 20:11:48 Re: Making the DB secure
Previous Message Rohit Gaddi 2005-06-20 19:48:33 index selection by query planner