First attempt: support for "\dg" in psql

From: Daniel Baldoni <pgsql(at)lcds(dot)com(dot)au>
To: pgsql-patches(at)postgresql(dot)org
Subject: First attempt: support for "\dg" in psql
Date: 2004-07-02 12:15:55
Message-ID: 40E551FB.E4A45E75@lcds.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

G'day folks,

Attached is my first attempt at providing "\du"-like functionality for
groups (i.e. a basic "\dg"). It's really just a copy of describeUsers().

It has one major limitation - members are listed by numeric id as I can't
think of a "cheap" way of turning the list into the corresponding list of
usernames.

I thought about having describeGroups() do a lookup on pg_user, but that
could become quite expensive if there is a large number of groups and/or
users (have I missed an obvious facility for caching this information?).

Also, the TODO mentions that the intention is to have \du list groups - I
assume that means output along the lines of the following is wanted?

List of database users
User name | User ID | Attributes | Groups
-----------+---------+----------------------------+---------------
test | 100 | superuser, create database | testg1, testg2

Getting the group names for \du or the usernames for \dg are both
relatively easy with the appropriate JOIN, but the result is always a set
of rows. How to turn that into a single array? What would be handy is a
a library function returning an array, which takes an array, a table and two
two columns from that table:
F(A,T,C1,C2) returning an array of T.C2 values, one for each
value of T.C1 found in A.

With regard to criticism, please be gentle - this is only my second
contribution (the first being a very minor update to to_char). ;-)

Ciao.

--
-------------------------------------------------------+---------------------
Daniel Baldoni BAppSc, PGradDipCompSci | Technical Director
require 'std/disclaimer.pl' | LcdS Pty. Ltd.
-------------------------------------------------------+ 856B Canning Hwy
Phone/FAX: +61-8-9364-8171 | Applecross
Mobile: 041-888-9794 | WA 6153
URL: http://www.lcds.com.au/ | Australia
-------------------------------------------------------+---------------------
"Any time there's something so ridiculous that no rational systems programmer
would even consider trying it, they send for me."; paraphrased from "King Of
The Murgos" by David Eddings. (I'm not good, just crazy)

Attachment Content-Type Size
pg.diff text/plain 5.3 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2004-07-02 13:26:11 Re: pg_autovacuum integration attempt #2
Previous Message Andreas Pflug 2004-07-02 07:41:05 Re: pg_tablespace_databases