Commit 0371d4d0 authored by Robert Haas's avatar Robert Haas

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
parent 0a803d65
...@@ -1272,7 +1272,9 @@ describeOneTableDetails(const char *schemaname, ...@@ -1272,7 +1272,9 @@ describeOneTableDetails(const char *schemaname,
else else
appendPQExpBuffer(&buf, ",\n NULL AS indexdef"); appendPQExpBuffer(&buf, ",\n NULL AS indexdef");
if (tableinfo.relkind == 'f' && pset.sversion >= 90200) if (tableinfo.relkind == 'f' && pset.sversion >= 90200)
appendPQExpBuffer(&buf, ",\n a.attfdwoptions"); appendPQExpBuffer(&buf, ",\n CASE WHEN attfdwoptions IS NULL THEN '' ELSE "
" '(' || array_to_string(ARRAY(SELECT quote_ident(option_name) || ' ' || quote_literal(option_value) FROM "
" pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions");
else else
appendPQExpBuffer(&buf, ",\n NULL AS attfdwoptions"); appendPQExpBuffer(&buf, ",\n NULL AS attfdwoptions");
if (verbose) if (verbose)
...@@ -2038,7 +2040,10 @@ describeOneTableDetails(const char *schemaname, ...@@ -2038,7 +2040,10 @@ describeOneTableDetails(const char *schemaname,
/* Footer information about foreign table */ /* Footer information about foreign table */
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf,
"SELECT s.srvname,\n" "SELECT s.srvname,\n"
" f.ftoptions\n" " array_to_string(ARRAY(SELECT "
" quote_ident(option_name) || ' ' || "
" quote_literal(option_value) FROM "
" pg_options_to_table(ftoptions)), ', ') "
"FROM pg_catalog.pg_foreign_table f,\n" "FROM pg_catalog.pg_foreign_table f,\n"
" pg_catalog.pg_foreign_server s\n" " pg_catalog.pg_foreign_server s\n"
"WHERE f.ftrelid = %s AND s.oid = f.ftserver;", "WHERE f.ftrelid = %s AND s.oid = f.ftserver;",
...@@ -2061,7 +2066,7 @@ describeOneTableDetails(const char *schemaname, ...@@ -2061,7 +2066,7 @@ describeOneTableDetails(const char *schemaname,
ftoptions = PQgetvalue(result, 0, 1); ftoptions = PQgetvalue(result, 0, 1);
if (ftoptions && ftoptions[0] != '\0') if (ftoptions && ftoptions[0] != '\0')
{ {
printfPQExpBuffer(&buf, "FDW Options: %s", ftoptions); printfPQExpBuffer(&buf, "FDW Options: (%s)", ftoptions);
printTableAddFooter(&cont, buf.data); printTableAddFooter(&cont, buf.data);
} }
PQclear(result); PQclear(result);
...@@ -3679,7 +3684,12 @@ listForeignDataWrappers(const char *pattern, bool verbose) ...@@ -3679,7 +3684,12 @@ listForeignDataWrappers(const char *pattern, bool verbose)
appendPQExpBuffer(&buf, ",\n "); appendPQExpBuffer(&buf, ",\n ");
printACLColumn(&buf, "fdwacl"); printACLColumn(&buf, "fdwacl");
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
",\n fdwoptions AS \"%s\"", ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
" '(' || array_to_string(ARRAY(SELECT "
" quote_ident(option_name) || ' ' || "
" quote_literal(option_value) FROM "
" pg_options_to_table(fdwoptions)), ', ') || ')' "
" END AS \"%s\"",
gettext_noop("FDW Options")); gettext_noop("FDW Options"));
if (pset.sversion >= 90100) if (pset.sversion >= 90100)
...@@ -3752,7 +3762,12 @@ listForeignServers(const char *pattern, bool verbose) ...@@ -3752,7 +3762,12 @@ listForeignServers(const char *pattern, bool verbose)
",\n" ",\n"
" s.srvtype AS \"%s\",\n" " s.srvtype AS \"%s\",\n"
" s.srvversion AS \"%s\",\n" " s.srvversion AS \"%s\",\n"
" s.srvoptions AS \"%s\",\n" " CASE WHEN srvoptions IS NULL THEN '' ELSE "
" '(' || array_to_string(ARRAY(SELECT "
" quote_ident(option_name) || ' ' || "
" quote_literal(option_value) FROM "
" pg_options_to_table(srvoptions)), ', ') || ')' "
" END AS \"%s\",\n"
" d.description AS \"%s\"", " d.description AS \"%s\"",
gettext_noop("Type"), gettext_noop("Type"),
gettext_noop("Version"), gettext_noop("Version"),
...@@ -3818,7 +3833,12 @@ listUserMappings(const char *pattern, bool verbose) ...@@ -3818,7 +3833,12 @@ listUserMappings(const char *pattern, bool verbose)
if (verbose) if (verbose)
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
",\n um.umoptions AS \"%s\"", ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
" '(' || array_to_string(ARRAY(SELECT "
" quote_ident(option_name) || ' ' || "
" quote_literal(option_value) FROM "
" pg_options_to_table(umoptions)), ', ') || ')' "
" END AS \"%s\"",
gettext_noop("FDW Options")); gettext_noop("FDW Options"));
appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_user_mappings um\n"); appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
...@@ -3873,7 +3893,12 @@ listForeignTables(const char *pattern, bool verbose) ...@@ -3873,7 +3893,12 @@ listForeignTables(const char *pattern, bool verbose)
if (verbose) if (verbose)
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
",\n ft.ftoptions AS \"%s\",\n" ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
" '(' || array_to_string(ARRAY(SELECT "
" quote_ident(option_name) || ' ' || "
" quote_literal(option_value) FROM "
" pg_options_to_table(ftoptions)), ', ') || ')' "
" END AS \"%s\",\n"
" d.description AS \"%s\"", " d.description AS \"%s\"",
gettext_noop("FDW Options"), gettext_noop("FDW Options"),
gettext_noop("Description")); gettext_noop("Description"));
......
This diff is collapsed.
...@@ -116,7 +116,7 @@ DROP FOREIGN DATA WRAPPER foo CASCADE; ...@@ -116,7 +116,7 @@ DROP FOREIGN DATA WRAPPER foo CASCADE;
-- exercise CREATE SERVER -- exercise CREATE SERVER
CREATE SERVER s1 FOREIGN DATA WRAPPER foo; -- ERROR CREATE SERVER s1 FOREIGN DATA WRAPPER foo; -- ERROR
CREATE FOREIGN DATA WRAPPER foo OPTIONS (test_wrapper 'true'); CREATE FOREIGN DATA WRAPPER foo OPTIONS ("test wrapper" 'true');
CREATE SERVER s1 FOREIGN DATA WRAPPER foo; CREATE SERVER s1 FOREIGN DATA WRAPPER foo;
CREATE SERVER s1 FOREIGN DATA WRAPPER foo; -- ERROR CREATE SERVER s1 FOREIGN DATA WRAPPER foo; -- ERROR
CREATE SERVER s2 FOREIGN DATA WRAPPER foo OPTIONS (host 'a', dbname 'b'); CREATE SERVER s2 FOREIGN DATA WRAPPER foo OPTIONS (host 'a', dbname 'b');
...@@ -154,7 +154,7 @@ ALTER SERVER s0; -- ERROR ...@@ -154,7 +154,7 @@ ALTER SERVER s0; -- ERROR
ALTER SERVER s0 OPTIONS (a '1'); -- ERROR ALTER SERVER s0 OPTIONS (a '1'); -- ERROR
ALTER SERVER s1 VERSION '1.0' OPTIONS (servername 's1'); ALTER SERVER s1 VERSION '1.0' OPTIONS (servername 's1');
ALTER SERVER s2 VERSION '1.1'; ALTER SERVER s2 VERSION '1.1';
ALTER SERVER s3 OPTIONS (tnsname 'orcl', port '1521'); ALTER SERVER s3 OPTIONS ("tns name" 'orcl', port '1521');
GRANT USAGE ON FOREIGN SERVER s1 TO regress_test_role; GRANT USAGE ON FOREIGN SERVER s1 TO regress_test_role;
GRANT USAGE ON FOREIGN SERVER s6 TO regress_test_role2 WITH GRANT OPTION; GRANT USAGE ON FOREIGN SERVER s6 TO regress_test_role2 WITH GRANT OPTION;
\des+ \des+
...@@ -210,7 +210,7 @@ CREATE USER MAPPING FOR regress_test_missing_role SERVER s1; -- ERROR ...@@ -210,7 +210,7 @@ CREATE USER MAPPING FOR regress_test_missing_role SERVER s1; -- ERROR
CREATE USER MAPPING FOR current_user SERVER s1; -- ERROR CREATE USER MAPPING FOR current_user SERVER s1; -- ERROR
CREATE USER MAPPING FOR current_user SERVER s4; CREATE USER MAPPING FOR current_user SERVER s4;
CREATE USER MAPPING FOR user SERVER s4; -- ERROR duplicate CREATE USER MAPPING FOR user SERVER s4; -- ERROR duplicate
CREATE USER MAPPING FOR public SERVER s4 OPTIONS (mapping 'is public'); CREATE USER MAPPING FOR public SERVER s4 OPTIONS ("this mapping" 'is public');
CREATE USER MAPPING FOR user SERVER s8 OPTIONS (username 'test', password 'secret'); -- ERROR CREATE USER MAPPING FOR user SERVER s8 OPTIONS (username 'test', password 'secret'); -- ERROR
CREATE USER MAPPING FOR user SERVER s8 OPTIONS (user 'test', password 'secret'); CREATE USER MAPPING FOR user SERVER s8 OPTIONS (user 'test', password 'secret');
ALTER SERVER s5 OWNER TO regress_test_role; ALTER SERVER s5 OWNER TO regress_test_role;
...@@ -264,10 +264,10 @@ CREATE FOREIGN TABLE ft1 () SERVER no_server; -- ERROR ...@@ -264,10 +264,10 @@ CREATE FOREIGN TABLE ft1 () SERVER no_server; -- ERROR
CREATE FOREIGN TABLE ft1 (c1 serial) SERVER sc; -- ERROR CREATE FOREIGN TABLE ft1 (c1 serial) SERVER sc; -- ERROR
CREATE FOREIGN TABLE ft1 () SERVER sc WITH OIDS; -- ERROR CREATE FOREIGN TABLE ft1 () SERVER sc WITH OIDS; -- ERROR
CREATE FOREIGN TABLE ft1 ( CREATE FOREIGN TABLE ft1 (
c1 integer OPTIONS (param1 'val1') NOT NULL, c1 integer OPTIONS ("param 1" 'val1') NOT NULL,
c2 text OPTIONS (param2 'val2', param3 'val3'), c2 text OPTIONS (param2 'val2', param3 'val3'),
c3 date c3 date
) SERVER sc OPTIONS (delimiter ',', quote '"'); ) SERVER sc OPTIONS (delimiter ',', quote '"', "be quoted" 'value');
COMMENT ON FOREIGN TABLE ft1 IS 'ft1'; COMMENT ON FOREIGN TABLE ft1 IS 'ft1';
COMMENT ON COLUMN ft1.c1 IS 'ft1.c1'; COMMENT ON COLUMN ft1.c1 IS 'ft1.c1';
\d+ ft1 \d+ ft1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment