Em Thu, 02 Jul 2009 15:27:33 -0400
Tom Lane <t...@sss.pgh.pa.us> escreveu:

> Peter Eisentraut <pete...@gmx.net> writes:
> > Looks good, but needs documentation and tab-complete.c updates, it
> > seems.  And you should revisit this patch to make it consistent
> > with the S flag that was added to most \d commands.  For example,
> > \dL would show only user-added languages, but \dLS would include c,
> > internal, and sql.
> 
> Another recent change in the \d support is that commands are expected
> to work (as best they can) for all server versions back to 7.4.  I
> didn't look to see if this patch needs any fixes for that, but it's
> something to keep in mind while reviewing.



  I applied the Tom Lane and Peter considerations, but I had that
remove one column (Owner) of out command \dL to compatibility with 7.4
version. The command \dLS output:

test=# \dLS
                                      List of languages
   Name   | Procedural Language |  Trusted  |     Call Handler     |
        Validator        
----------+---------------------+-----------+----------------------+
-------------------------
 c        | Untrusted           | Untrusted |                      |
 fmgr_c_validator
 internal | Untrusted           | Untrusted |                      |
 fmgr_internal_validator
 plperl   | Trusted             | Trusted   | plperl_call_handler  |
 plperl_validator
 plpgsql  | Trusted             | Trusted   | plpgsql_call_handler |
 plpgsql_validator
 pltcl    | Trusted             | Trusted   | pltcl_call_handler   |
 
 sql      | Untrusted           | Trusted   |                      |
 fmgr_sql_validator
(6 rows)

test=# 


  Comments?

  

Best Regards,
-- 
Fernando Ike
*** a/doc/src/sgml/ref/psql-ref.sgml
--- b/doc/src/sgml/ref/psql-ref.sgml
***************
*** 1179,1184 **** testdb=&gt;
--- 1179,1194 ----
  
  
        <varlistentry>
+         <term><literal>\dL[S+]</literal></term>
+         <listitem>
+         <para>
+ 		Lists all procedural languages. By default, only user-created languages are shown; supply the <literal>S</literal> modifier to include system objects. If <literal>+</literal> is appended to the command line, each language is listed with its associated permissions
+         </para>
+         </listitem>
+       </varlistentry>
+ 
+ 
+       <varlistentry>
          <term><literal>\dn[+] [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
  
          <listitem>
*** a/src/bin/psql/command.c
--- b/src/bin/psql/command.c
***************
*** 390,395 **** exec_command(const char *cmd,
--- 390,398 ----
  			case 'l':
  				success = do_lo_list();
  				break;
+ 			case 'L':
+ 				success = listLanguages(pattern, show_verbose, show_system);
+ 				break;
  			case 'n':
  				success = listSchemas(pattern, show_verbose);
  				break;
*** a/src/bin/psql/describe.c
--- b/src/bin/psql/describe.c
***************
*** 2261,2266 **** listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
--- 2261,2324 ----
  }
  
  
+ /* \dL
+ * 
+ * Describes Languages.
+ */
+ bool
+ listLanguages(const char *pattern, bool verbose, bool showSystem)
+ {
+     PQExpBufferData buf;
+     PGresult *res;
+     printQueryOpt myopt = pset.popt;
+ 
+     initPQExpBuffer(&buf);
+ 
+     printfPQExpBuffer(&buf,
+                                     "SELECT l.lanname as \"%s\",\n"
+                                     "       CASE WHEN l.lanispl = 't' THEN 'Trusted' WHEN l.lanispl = 'f' THEN 'Untrusted' END AS \"%s\",\n"
+                                     "       CASE WHEN l.lanpltrusted='t' THEN 'Trusted' WHEN lanpltrusted='f' THEN 'Untrusted' END AS \"%s\",\n"
+                                     "       CASE WHEN p.oid = 0 THEN NULL ELSE p.proname END AS \"%s\",\n"
+                                     "       CASE WHEN q.oid = 0 THEN NULL ELSE q.proname END AS \"%s\"\n",
+                                     gettext_noop("Name"),
+                                     gettext_noop("Procedural Language"),
+                                     gettext_noop("Trusted"),
+                                     gettext_noop("Call Handler"),
+                                     gettext_noop("Validator"));
+ 
+     if (verbose)
+     {
+             appendPQExpBuffer(&buf, ",\n");
+             printACLColumn(&buf, "l.lanacl");
+     }
+ 
+     appendPQExpBuffer(&buf, " FROM pg_catalog.pg_language l\n");
+     appendPQExpBuffer(&buf, "  LEFT JOIN pg_catalog.pg_proc p on l.lanplcallfoid = p.oid\n");
+     appendPQExpBuffer(&buf, "  LEFT JOIN pg_catalog.pg_proc q on l.lanvalidator = q.oid\n");
+ 
+     processSQLNamePattern(pset.db, &buf, pattern, false, false,
+                                               NULL, "l.lanname", NULL, NULL);
+ 	if (!showSystem && !pattern)
+ 	appendPQExpBuffer(&buf, "WHERE lanplcallfoid != 0");
+     appendPQExpBuffer(&buf, " ORDER BY 1;");
+ 
+     res = PSQLexec(buf.data, false);
+     termPQExpBuffer(&buf);
+     if (!res)
+             return false;
+ 
+     myopt.nullPrint = NULL;
+     myopt.title = _("List of languages");
+     myopt.translate_header = true;
+ 
+     printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ 
+     PQclear(res);
+     return true;
+ 
+ }
+ 
+ 
  /*
   * \dD
   *
*** a/src/bin/psql/describe.h
--- b/src/bin/psql/describe.h
***************
*** 75,79 **** extern bool listForeignServers(const char *pattern, bool verbose);
--- 75,81 ----
  /* \deu */
  extern bool listUserMappings(const char *pattern, bool verbose);
  
+ /* \dL */
+ extern bool listLanguages(const char *pattern, bool verbose, bool showSystem);
  
  #endif   /* DESCRIBE_H */
*** a/src/bin/psql/help.c
--- b/src/bin/psql/help.c
***************
*** 213,218 **** slashUsage(unsigned short int pager)
--- 213,219 ----
  	fprintf(output, _("  \\dg     [PATTERN]      list roles (groups)\n"));
  	fprintf(output, _("  \\di[S+] [PATTERN]      list indexes\n"));
  	fprintf(output, _("  \\dl                    list large objects, same as \\lo_list\n"));
+ 	fprintf(output, _("  \\dL[S+]                list (procedural) languages\n"));
  	fprintf(output, _("  \\dn[+]  [PATTERN]      list schemas\n"));
  	fprintf(output, _("  \\do[S]  [PATTERN]      list operators\n"));
  	fprintf(output, _("  \\dp     [PATTERN]      list table, view, and sequence access privileges\n"));
*** a/src/bin/psql/tab-complete.c
--- b/src/bin/psql/tab-complete.c
***************
*** 628,634 **** psql_completion(char *text, int start, int end)
  	static const char *const backslash_commands[] = {
  		"\\a", "\\connect", "\\C", "\\cd", "\\copy", "\\copyright",
  		"\\d", "\\da", "\\db", "\\dc", "\\dC", "\\dd", "\\dD", "\\des", "\\deu", "\\dew", "\\df",
! 		"\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl",
  		"\\dn", "\\do", "\\dp", "\\ds", "\\dS", "\\dt", "\\dT", "\\dv", "\\du",
  		"\\e", "\\echo", "\\ef", "\\encoding",
  		"\\f", "\\g", "\\h", "\\help", "\\H", "\\i", "\\l",
--- 628,634 ----
  	static const char *const backslash_commands[] = {
  		"\\a", "\\connect", "\\C", "\\cd", "\\copy", "\\copyright",
  		"\\d", "\\da", "\\db", "\\dc", "\\dC", "\\dd", "\\dD", "\\des", "\\deu", "\\dew", "\\df",
! 		"\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl", "\\dL",
  		"\\dn", "\\do", "\\dp", "\\ds", "\\dS", "\\dt", "\\dT", "\\dv", "\\du",
  		"\\e", "\\echo", "\\ef", "\\encoding",
  		"\\f", "\\g", "\\h", "\\help", "\\H", "\\i", "\\l",
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to