Skip to content

Commit 0371d4d

Browse files
committed
Change format of SQL/MED generic options in psql backslash commands.
Rather than dumping out the raw array as PostgreSQL represents it internally, we now print it out in a format similar to the one in which the user input it, which seems a lot more user friendly. Shigeru Hanada
1 parent 0a803d6 commit 0371d4d

File tree

3 files changed

+210
-184
lines changed

3 files changed

+210
-184
lines changed

src/bin/psql/describe.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,9 @@ describeOneTableDetails(const char *schemaname,
12721272
else
12731273
appendPQExpBuffer(&buf, ",\n NULL AS indexdef");
12741274
if (tableinfo.relkind == 'f' && pset.sversion >= 90200)
1275-
appendPQExpBuffer(&buf, ",\n a.attfdwoptions");
1275+
appendPQExpBuffer(&buf, ",\n CASE WHEN attfdwoptions IS NULL THEN '' ELSE "
1276+
" '(' || array_to_string(ARRAY(SELECT quote_ident(option_name) || ' ' || quote_literal(option_value) FROM "
1277+
" pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions");
12761278
else
12771279
appendPQExpBuffer(&buf, ",\n NULL AS attfdwoptions");
12781280
if (verbose)
@@ -2038,7 +2040,10 @@ describeOneTableDetails(const char *schemaname,
20382040
/* Footer information about foreign table */
20392041
printfPQExpBuffer(&buf,
20402042
"SELECT s.srvname,\n"
2041-
" f.ftoptions\n"
2043+
" array_to_string(ARRAY(SELECT "
2044+
" quote_ident(option_name) || ' ' || "
2045+
" quote_literal(option_value) FROM "
2046+
" pg_options_to_table(ftoptions)), ', ') "
20422047
"FROM pg_catalog.pg_foreign_table f,\n"
20432048
" pg_catalog.pg_foreign_server s\n"
20442049
"WHERE f.ftrelid = %s AND s.oid = f.ftserver;",
@@ -2061,7 +2066,7 @@ describeOneTableDetails(const char *schemaname,
20612066
ftoptions = PQgetvalue(result, 0, 1);
20622067
if (ftoptions && ftoptions[0] != '\0')
20632068
{
2064-
printfPQExpBuffer(&buf, "FDW Options: %s", ftoptions);
2069+
printfPQExpBuffer(&buf, "FDW Options: (%s)", ftoptions);
20652070
printTableAddFooter(&cont, buf.data);
20662071
}
20672072
PQclear(result);
@@ -3679,7 +3684,12 @@ listForeignDataWrappers(const char *pattern, bool verbose)
36793684
appendPQExpBuffer(&buf, ",\n ");
36803685
printACLColumn(&buf, "fdwacl");
36813686
appendPQExpBuffer(&buf,
3682-
",\n fdwoptions AS \"%s\"",
3687+
",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
3688+
" '(' || array_to_string(ARRAY(SELECT "
3689+
" quote_ident(option_name) || ' ' || "
3690+
" quote_literal(option_value) FROM "
3691+
" pg_options_to_table(fdwoptions)), ', ') || ')' "
3692+
" END AS \"%s\"",
36833693
gettext_noop("FDW Options"));
36843694

36853695
if (pset.sversion >= 90100)
@@ -3752,7 +3762,12 @@ listForeignServers(const char *pattern, bool verbose)
37523762
",\n"
37533763
" s.srvtype AS \"%s\",\n"
37543764
" s.srvversion AS \"%s\",\n"
3755-
" s.srvoptions AS \"%s\",\n"
3765+
" CASE WHEN srvoptions IS NULL THEN '' ELSE "
3766+
" '(' || array_to_string(ARRAY(SELECT "
3767+
" quote_ident(option_name) || ' ' || "
3768+
" quote_literal(option_value) FROM "
3769+
" pg_options_to_table(srvoptions)), ', ') || ')' "
3770+
" END AS \"%s\",\n"
37563771
" d.description AS \"%s\"",
37573772
gettext_noop("Type"),
37583773
gettext_noop("Version"),
@@ -3818,7 +3833,12 @@ listUserMappings(const char *pattern, bool verbose)
38183833

38193834
if (verbose)
38203835
appendPQExpBuffer(&buf,
3821-
",\n um.umoptions AS \"%s\"",
3836+
",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
3837+
" '(' || array_to_string(ARRAY(SELECT "
3838+
" quote_ident(option_name) || ' ' || "
3839+
" quote_literal(option_value) FROM "
3840+
" pg_options_to_table(umoptions)), ', ') || ')' "
3841+
" END AS \"%s\"",
38223842
gettext_noop("FDW Options"));
38233843

38243844
appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
@@ -3873,7 +3893,12 @@ listForeignTables(const char *pattern, bool verbose)
38733893

38743894
if (verbose)
38753895
appendPQExpBuffer(&buf,
3876-
",\n ft.ftoptions AS \"%s\",\n"
3896+
",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
3897+
" '(' || array_to_string(ARRAY(SELECT "
3898+
" quote_ident(option_name) || ' ' || "
3899+
" quote_literal(option_value) FROM "
3900+
" pg_options_to_table(ftoptions)), ', ') || ')' "
3901+
" END AS \"%s\",\n"
38773902
" d.description AS \"%s\"",
38783903
gettext_noop("FDW Options"),
38793904
gettext_noop("Description"));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy