Hi hackers,

It occurred to me that psql's \z command could benefit from the
addition of some newlines.  With any more than one grantee per object,
the output of \z rapidly becomes extremely wide, and very hard to
read.

I'd like to split the output onto one line per grantee.  So, instead of this:

 Schema | Name | Type  |                            Access privileges
--------+------+-------+-------------------------------------------------------------------------
 public | a    | table |
{brendanjurd=arwdxt/brendanjurd,foo=arwd/brendanjurd,bar=r/brendanjurd}
 public | b    | table | {brendanjurd=arwdxt/brendanjurd,foo=arwd/brendanjurd}
(2 rows)

You would get this:

 Schema | Name | Type  |       Access privileges
--------+------+-------+--------------------------------
 public | a    | table | brendanjurd=arwdxt/brendanjurd
                       : foo=arwd/brendanjurd
                       : bar=r/brendanjurd
 public | b    | table | brendanjurd=arwdxt/brendanjurd
                       : foo=arwd/brendanjurd
(2 rows)

Because the -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ACLs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: http://getfiregpg.org

iD8DBQFIB3kL5YBsbHkuyV0RAgWQAJ9bcl3bOFozvi9LxRAQN1OwT3t+QgCcCGVq
dcMw3wIBQVPv1nYDBCSRpDA=
=s1eD
-----END PGP SIGNATURE-----
 are stored as an array, the patch to achieve this is trivial (see attached).

Looking forward to your comments.

Added to wiki.

Cheers,
BJ
*** src/bin/psql/describe.c
--- src/bin/psql/describe.c
***************
*** 482,488 **** permissionsList(const char *pattern)
                                          "SELECT n.nspname as \"%s\",\n"
                                          "  c.relname as \"%s\",\n"
                                          "  CASE c.relkind WHEN 'r' THEN '%s' 
WHEN 'v' THEN '%s' WHEN 'S' THEN '%s' END as \"%s\",\n"
!                                         "  c.relacl as \"%s\"\n"
                                          "FROM pg_catalog.pg_class c\n"
           "     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = 
c.relnamespace\n"
                                          "WHERE c.relkind IN ('r', 'v', 
'S')\n",
--- 482,488 ----
                                          "SELECT n.nspname as \"%s\",\n"
                                          "  c.relname as \"%s\",\n"
                                          "  CASE c.relkind WHEN 'r' THEN '%s' 
WHEN 'v' THEN '%s' WHEN 'S' THEN '%s' END as \"%s\",\n"
!                                         "  array_to_string(c.relacl, chr(10)) 
as \"%s\"\n"
                                          "FROM pg_catalog.pg_class c\n"
           "     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = 
c.relnamespace\n"
                                          "WHERE c.relkind IN ('r', 'v', 
'S')\n",
*** src/test/regress/expected/dependency.out
--- src/test/regress/expected/dependency.out
***************
*** 68,86 **** NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index 
"deptest_pkey" fo
  GRANT ALL ON deptest1 TO regression_user2;
  RESET SESSION AUTHORIZATION;
  \z deptest1
!                                                           Access privileges 
for database "regression"
!  Schema |   Name   | Type  |                                                  
       Access privileges                                                        
  
! 
--------+----------+-------+------------------------------------------------------------------------------------------------------------------------------------
!  public | deptest1 | table | 
{regression_user0=arwdxt/regression_user0,regression_user1=a*r*w*d*x*t*/regression_user0,regression_user2=arwdxt/regression_user1}
  (1 row)
  
  DROP OWNED BY regression_user1;
  -- all grants revoked
  \z deptest1
!               Access privileges for database "regression"
!  Schema |   Name   | Type  |             Access privileges              
! --------+----------+-------+--------------------------------------------
!  public | deptest1 | table | {regression_user0=arwdxt/regression_user0}
  (1 row)
  
  -- table was dropped
--- 68,88 ----
  GRANT ALL ON deptest1 TO regression_user2;
  RESET SESSION AUTHORIZATION;
  \z deptest1
!                 Access privileges for database "regression"
!  Schema |   Name   | Type  |               Access privileges                
! --------+----------+-------+------------------------------------------------
!  public | deptest1 | table | regression_user0=arwdxt/regression_user0
!                            : regression_user1=a*r*w*d*x*t*/regression_user0
!                            : regression_user2=arwdxt/regression_user1
  (1 row)
  
  DROP OWNED BY regression_user1;
  -- all grants revoked
  \z deptest1
!              Access privileges for database "regression"
!  Schema |   Name   | Type  |            Access privileges             
! --------+----------+-------+------------------------------------------
!  public | deptest1 | table | regression_user0=arwdxt/regression_user0
  (1 row)
  
  -- table was dropped
-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches

Reply via email to