Add new psql command \dL to list languages.
authorRobert Haas <rhaas@postgresql.org>
Thu, 20 Jan 2011 05:00:30 +0000 (00:00 -0500)
committerRobert Haas <rhaas@postgresql.org>
Thu, 20 Jan 2011 05:00:30 +0000 (00:00 -0500)
Original patch by Fernando Ike, revived by Josh Kuperschmidt, reviewed by Andreas
Karlsson, and in earlier versions by Tom Lane and Peter Eisentraut.

doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/command.c
src/bin/psql/describe.c
src/bin/psql/describe.h
src/bin/psql/help.c
src/bin/psql/tab-complete.c

index 5f61561eea5cb8d803d23007f893c335bbd175b1..30d4507eb3b4aaf6fc686c71a8f532ab31df7ca7 100644 (file)
@@ -1249,6 +1249,21 @@ testdb=&gt;
         </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><literal>\dL[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <listitem>
+        <para>
+        Lists all procedural languages. If <replaceable
+        class="parameter">pattern</replaceable>
+        is specified, only languages whose names match the pattern are listed.
+        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 name, each
+        language is listed with its call handler, validator, access privileges,
+        and whether it is a system object.
+        </para>
+        </listitem>
+      </varlistentry>
 
       <varlistentry>
         <term><literal>\dn[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
index 962c13c13606360fe358657e474a412266379eed..301dc11bcc2f7101663267d2e8fbad5f4ad497b8 100644 (file)
@@ -416,6 +416,9 @@ exec_command(const char *cmd,
            case 'l':
                success = do_lo_list();
                break;
+           case 'L':
+               success = listLanguages(pattern, show_verbose, show_system);
+               break;
            case 'n':
                success = listSchemas(pattern, show_verbose, show_system);
                break;
index 205190f729e48e1fb7ff27d56ca4bb59e73e45fa..e9436f862a32eddbecaf00a555e15837dbf40295 100644 (file)
@@ -2566,6 +2566,74 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
 }
 
 
+/*
+ * \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",
+                     gettext_noop("Name"));
+   if (pset.sversion >= 80300)
+           appendPQExpBuffer(&buf,
+                             "       pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n",
+                             gettext_noop("Owner"));
+
+   appendPQExpBuffer(&buf,
+                     "       l.lanpltrusted AS \"%s\"",
+                     gettext_noop("Trusted"));
+
+   if (verbose)
+   {
+           appendPQExpBuffer(&buf,
+                             ",\n       NOT l.lanispl AS \"%s\",\n"
+                             "       l.lanplcallfoid::regprocedure AS \"%s\",\n"
+                             "       l.lanvalidator::regprocedure AS \"%s\",\n       ",
+                             gettext_noop("Internal Language"),
+                             gettext_noop("Call Handler"),
+                             gettext_noop("Validator"));
+           if (pset.sversion >= 90000)
+               appendPQExpBuffer(&buf, "l.laninline::regprocedure AS \"%s\",\n       ",
+                                 gettext_noop("Inline Handler"));
+           printACLColumn(&buf, "l.lanacl");
+   }
+
+   appendPQExpBuffer(&buf,
+                     "\nFROM pg_catalog.pg_language l\n");
+
+   processSQLNamePattern(pset.db, &buf, pattern, false, false,
+                         NULL, "l.lanname", NULL, NULL);
+
+   if (!showSystem && !pattern)
+       appendPQExpBuffer(&buf, "WHERE lanplcallfoid != 0\n");
+
+   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
  *
index 2029ef848dff2c1b0363b4440715278f2a44939e..4e80bcf41f86d8be9f3fb07b9522b17d0616e44e 100644 (file)
@@ -84,5 +84,7 @@ extern bool listUserMappings(const char *pattern, bool verbose);
 /* \det */
 extern bool listForeignTables(const char *pattern, bool verbose);
 
+/* \dL */
+extern bool listLanguages(const char *pattern, bool verbose, bool showSystem);
 
 #endif   /* DESCRIBE_H */
index 96c85a25d6c944ef5ddd53c24ceb0cddada4ebb3..bd5c4b767baeb1eccba5c4ba5e74860f5206672c 100644 (file)
@@ -211,6 +211,7 @@ slashUsage(unsigned short int pager)
    fprintf(output, _("  \\dg[+]  [PATTERN]      list roles\n"));
    fprintf(output, _("  \\di[S+] [PATTERN]      list indexes\n"));
    fprintf(output, _("  \\dl                    list large objects, same as \\lo_list\n"));
+   fprintf(output, _("  \\dL[S+] [PATTERN]      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"));
index 8c15838555377fd0ca19d05e92fb95cd847a068a..84c68a7bff283240d179bf2e67ec52a1a85abd7a 100644 (file)
@@ -713,7 +713,7 @@ psql_completion(char *text, int start, int end)
    static const char *const backslash_commands[] = {
        "\\a", "\\connect", "\\conninfo", "\\C", "\\cd", "\\copy", "\\copyright",
        "\\d", "\\da", "\\db", "\\dc", "\\dC", "\\dd", "\\dD", "\\des", "\\det", "\\deu", "\\dew", "\\df",
-       "\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl",
+       "\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl", "\\dL",
        "\\dn", "\\do", "\\dp", "\\drds", "\\ds", "\\dS", "\\dt", "\\dT", "\\dv", "\\du",
        "\\e", "\\echo", "\\ef", "\\encoding",
        "\\f", "\\g", "\\h", "\\help", "\\H", "\\i", "\\l",
@@ -2680,6 +2680,8 @@ psql_completion(char *text, int start, int end)
 
    else if (strncmp(prev_wd, "\\di", strlen("\\di")) == 0)
        COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
+   else if (strncmp(prev_wd, "\\dL", strlen("\\dL")) == 0)
+       COMPLETE_WITH_QUERY(Query_for_list_of_languages);
    else if (strncmp(prev_wd, "\\dn", strlen("\\dn")) == 0)
        COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
    else if (strncmp(prev_wd, "\\dp", strlen("\\dp")) == 0