Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9c5e2c1

Browse files
committed
Add new psql command \dL to list languages.
Original patch by Fernando Ike, revived by Josh Kuperschmidt, reviewed by Andreas Karlsson, and in earlier versions by Tom Lane and Peter Eisentraut.
1 parent 92f7eeb commit 9c5e2c1

File tree

6 files changed

+92
-1
lines changed

6 files changed

+92
-1
lines changed

doc/src/sgml/ref/psql-ref.sgml

+15
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,21 @@ testdb=>
12491249
</listitem>
12501250
</varlistentry>
12511251

1252+
<varlistentry>
1253+
<term><literal>\dL[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1254+
<listitem>
1255+
<para>
1256+
Lists all procedural languages. If <replaceable
1257+
class="parameter">pattern</replaceable>
1258+
is specified, only languages whose names match the pattern are listed.
1259+
By default, only user-created languages
1260+
are shown; supply the <literal>S</literal> modifier to include system
1261+
objects. If <literal>+</literal> is appended to the command name, each
1262+
language is listed with its call handler, validator, access privileges,
1263+
and whether it is a system object.
1264+
</para>
1265+
</listitem>
1266+
</varlistentry>
12521267

12531268
<varlistentry>
12541269
<term><literal>\dn[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>

src/bin/psql/command.c

+3
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ exec_command(const char *cmd,
416416
case 'l':
417417
success = do_lo_list();
418418
break;
419+
case 'L':
420+
success = listLanguages(pattern, show_verbose, show_system);
421+
break;
419422
case 'n':
420423
success = listSchemas(pattern, show_verbose, show_system);
421424
break;

src/bin/psql/describe.c

+68
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,74 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
25662566
}
25672567

25682568

2569+
/*
2570+
* \dL
2571+
*
2572+
* Describes languages.
2573+
*/
2574+
bool
2575+
listLanguages(const char *pattern, bool verbose, bool showSystem)
2576+
{
2577+
PQExpBufferData buf;
2578+
PGresult *res;
2579+
printQueryOpt myopt = pset.popt;
2580+
2581+
initPQExpBuffer(&buf);
2582+
2583+
printfPQExpBuffer(&buf,
2584+
"SELECT l.lanname AS \"%s\",\n",
2585+
gettext_noop("Name"));
2586+
if (pset.sversion >= 80300)
2587+
appendPQExpBuffer(&buf,
2588+
" pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n",
2589+
gettext_noop("Owner"));
2590+
2591+
appendPQExpBuffer(&buf,
2592+
" l.lanpltrusted AS \"%s\"",
2593+
gettext_noop("Trusted"));
2594+
2595+
if (verbose)
2596+
{
2597+
appendPQExpBuffer(&buf,
2598+
",\n NOT l.lanispl AS \"%s\",\n"
2599+
" l.lanplcallfoid::regprocedure AS \"%s\",\n"
2600+
" l.lanvalidator::regprocedure AS \"%s\",\n ",
2601+
gettext_noop("Internal Language"),
2602+
gettext_noop("Call Handler"),
2603+
gettext_noop("Validator"));
2604+
if (pset.sversion >= 90000)
2605+
appendPQExpBuffer(&buf, "l.laninline::regprocedure AS \"%s\",\n ",
2606+
gettext_noop("Inline Handler"));
2607+
printACLColumn(&buf, "l.lanacl");
2608+
}
2609+
2610+
appendPQExpBuffer(&buf,
2611+
"\nFROM pg_catalog.pg_language l\n");
2612+
2613+
processSQLNamePattern(pset.db, &buf, pattern, false, false,
2614+
NULL, "l.lanname", NULL, NULL);
2615+
2616+
if (!showSystem && !pattern)
2617+
appendPQExpBuffer(&buf, "WHERE lanplcallfoid != 0\n");
2618+
2619+
appendPQExpBuffer(&buf, "ORDER BY 1;");
2620+
2621+
res = PSQLexec(buf.data, false);
2622+
termPQExpBuffer(&buf);
2623+
if (!res)
2624+
return false;
2625+
2626+
myopt.nullPrint = NULL;
2627+
myopt.title = _("List of languages");
2628+
myopt.translate_header = true;
2629+
2630+
printQuery(res, &myopt, pset.queryFout, pset.logfile);
2631+
2632+
PQclear(res);
2633+
return true;
2634+
}
2635+
2636+
25692637
/*
25702638
* \dD
25712639
*

src/bin/psql/describe.h

+2
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,7 @@ extern bool listUserMappings(const char *pattern, bool verbose);
8484
/* \det */
8585
extern bool listForeignTables(const char *pattern, bool verbose);
8686

87+
/* \dL */
88+
extern bool listLanguages(const char *pattern, bool verbose, bool showSystem);
8789

8890
#endif /* DESCRIBE_H */

src/bin/psql/help.c

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ slashUsage(unsigned short int pager)
211211
fprintf(output, _(" \\dg[+] [PATTERN] list roles\n"));
212212
fprintf(output, _(" \\di[S+] [PATTERN] list indexes\n"));
213213
fprintf(output, _(" \\dl list large objects, same as \\lo_list\n"));
214+
fprintf(output, _(" \\dL[S+] [PATTERN] list procedural languages\n"));
214215
fprintf(output, _(" \\dn[+] [PATTERN] list schemas\n"));
215216
fprintf(output, _(" \\do[S] [PATTERN] list operators\n"));
216217
fprintf(output, _(" \\dp [PATTERN] list table, view, and sequence access privileges\n"));

src/bin/psql/tab-complete.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ psql_completion(char *text, int start, int end)
713713
static const char *const backslash_commands[] = {
714714
"\\a", "\\connect", "\\conninfo", "\\C", "\\cd", "\\copy", "\\copyright",
715715
"\\d", "\\da", "\\db", "\\dc", "\\dC", "\\dd", "\\dD", "\\des", "\\det", "\\deu", "\\dew", "\\df",
716-
"\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl",
716+
"\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl", "\\dL",
717717
"\\dn", "\\do", "\\dp", "\\drds", "\\ds", "\\dS", "\\dt", "\\dT", "\\dv", "\\du",
718718
"\\e", "\\echo", "\\ef", "\\encoding",
719719
"\\f", "\\g", "\\h", "\\help", "\\H", "\\i", "\\l",
@@ -2680,6 +2680,8 @@ psql_completion(char *text, int start, int end)
26802680

26812681
else if (strncmp(prev_wd, "\\di", strlen("\\di")) == 0)
26822682
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
2683+
else if (strncmp(prev_wd, "\\dL", strlen("\\dL")) == 0)
2684+
COMPLETE_WITH_QUERY(Query_for_list_of_languages);
26832685
else if (strncmp(prev_wd, "\\dn", strlen("\\dn")) == 0)
26842686
COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
26852687
else if (strncmp(prev_wd, "\\dp", strlen("\\dp")) == 0

0 commit comments

Comments
 (0)