First attempt: support for "\dg" in psql

Started by Daniel Baldoniabout 22 years ago7 messagespatches
Jump to latest
#1Daniel Baldoni
pgsql@lcds.com.au

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)

Attachments:

pg.difftext/plain; charset=us-ascii; name=pg.diffDownload+59-2
#2Markus Bertheau
twanger@bluetwanger.de
In reply to: Daniel Baldoni (#1)
Re: First attempt: support for "\dg" in psql

This is already in:

http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/bin/psql/describe.c.diff?r1=text&tr1=1.89&r2=text&tr2=1.90&f=h

The - in front of that item on the todo list[1]http://developer.postgresql.org/todo.php means that it's already
done. This information probably needs to appear more prominently on the
todo page.

[1]: http://developer.postgresql.org/todo.php

Thanks.

--
Markus Bertheau <twanger@bluetwanger.de>

#3Bruce Momjian
bruce@momjian.us
In reply to: Markus Bertheau (#2)
Re: First attempt: support for "\dg" in psql

I have moved the mention of the dash higher in the TODO file.

---------------------------------------------------------------------------

Markus Bertheau wrote:

This is already in:

http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/bin/psql/describe.c.diff?r1=text&amp;tr1=1.89&amp;r2=text&amp;tr2=1.90&amp;f=h

The - in front of that item on the todo list[1] means that it's already
done. This information probably needs to appear more prominently on the
todo page.

[1] http://developer.postgresql.org/todo.php

Thanks.

--
Markus Bertheau <twanger@bluetwanger.de>

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

!DSPAM:40e56844212136178011369!

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#4Andrew Dunstan
andrew@dunslane.net
In reply to: Bruce Momjian (#3)
Re: First attempt: support for '\dg' in psql

Bruce Momjian said:

I have moved the mention of the dash higher in the TODO file.

Maybe you could put the dash in a different color (red?) so it stands out
more. Or maybe the whole item could go in a different color if done.

cheers

andrew

#5Markus Bertheau
twanger@bluetwanger.de
In reply to: Andrew Dunstan (#4)
Re: First attempt: support for '\dg' in psql

В Втр, 06.07.2004, в 19:09, Andrew Dunstan пишет:

Bruce Momjian said:

I have moved the mention of the dash higher in the TODO file.

Maybe you could put the dash in a different color (red?) so it stands out
more. Or maybe the whole item could go in a different color if done.

Yes, what about stroke through:

done TODO item

--
Markus Bertheau <twanger@bluetwanger.de>

#6Christopher Kings-Lynne
chriskl@familyhealth.com.au
In reply to: Markus Bertheau (#5)
Re: First attempt: support for '\dg' in psql

I have moved the mention of the dash higher in the TODO file.

Maybe you could put the dash in a different color (red?) so it stands out
more. Or maybe the whole item could go in a different color if done./

Yes, what about stroke through:

Because neither works in the plain text version.

Chris

#7Bruce Momjian
bruce@momjian.us
In reply to: Christopher Kings-Lynne (#6)
Re: First attempt: support for '\dg' in psql

Christopher Kings-Lynne wrote:

I have moved the mention of the dash higher in the TODO file.

Maybe you could put the dash in a different color (red?) so it stands out
more. Or maybe the whole item could go in a different color if done./

Yes, what about stroke through:

Because neither works in the plain text version.

OK, I updated to the newest version of txt2html and got the line to
appear in bold.

I also removed some blank lines and reordered the descriptions:

http://developer.postgresql.org/todo.php

Any other suggestions on how to improve this?

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073