]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix issues with describe queries of extended statistics in psql
authorMichael Paquier <michael@paquier.xyz>
Sat, 8 Jan 2022 07:45:14 +0000 (16:45 +0900)
committerMichael Paquier <michael@paquier.xyz>
Sat, 8 Jan 2022 07:45:14 +0000 (16:45 +0900)
This addresses some problems in the describe queries used for extended
statistics:
- Two schema qualifications for the text type were missing for \dX.
- The list of extended statistics listed for a table through \d was
ordered based on the object OIDs, but it is more consistent with the
other commands to order by namespace and then by object name.
- A couple of aliases were not used in \d.  These are removed.

This is similar to commits 1f092a3 and 07f8a9e.

Author: Justin Pryzby
Discussion: https://postgr.es/m/20220107022235.GA14051@telsasoft.com
Backpatch-through: 14

src/bin/psql/describe.c

index ac4247680c831046186054df5a0b40556fff6378..48348750ee38363ff4c83e3e9638aceff1d6a9d1 100644 (file)
@@ -2879,16 +2879,16 @@ describeOneTableDetails(const char *schemaname,
                        printfPQExpBuffer(&buf,
                                                          "SELECT oid, "
                                                          "stxrelid::pg_catalog.regclass, "
-                                                         "stxnamespace::pg_catalog.regnamespace AS nsp, "
+                                                         "stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS nsp, "
                                                          "stxname,\n"
                                                          "pg_catalog.pg_get_statisticsobjdef_columns(oid) AS columns,\n"
                                                          "  'd' = any(stxkind) AS ndist_enabled,\n"
                                                          "  'f' = any(stxkind) AS deps_enabled,\n"
                                                          "  'm' = any(stxkind) AS mcv_enabled,\n"
                                                          "stxstattarget\n"
-                                                         "FROM pg_catalog.pg_statistic_ext stat\n"
+                                                         "FROM pg_catalog.pg_statistic_ext\n"
                                                          "WHERE stxrelid = '%s'\n"
-                                                         "ORDER BY 1;",
+                                                         "ORDER BY nsp, stxname;",
                                                          oid);
 
                        result = PSQLexec(buf.data);
@@ -2990,7 +2990,7 @@ describeOneTableDetails(const char *schemaname,
                                appendPQExpBufferStr(&buf, "  stxstattarget\n");
                        else
                                appendPQExpBufferStr(&buf, "  -1 AS stxstattarget\n");
-                       appendPQExpBuffer(&buf, "FROM pg_catalog.pg_statistic_ext stat\n"
+                       appendPQExpBuffer(&buf, "FROM pg_catalog.pg_statistic_ext\n"
                                                          "WHERE stxrelid = '%s'\n"
                                                          "ORDER BY 1;",
                                                          oid);
@@ -4726,7 +4726,7 @@ listExtendedStats(const char *pattern)
        initPQExpBuffer(&buf);
        printfPQExpBuffer(&buf,
                                          "SELECT \n"
-                                         "es.stxnamespace::pg_catalog.regnamespace::text AS \"%s\", \n"
+                                         "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
                                          "es.stxname AS \"%s\", \n",
                                          gettext_noop("Schema"),
                                          gettext_noop("Name"));
@@ -4773,7 +4773,7 @@ listExtendedStats(const char *pattern)
 
        processSQLNamePattern(pset.db, &buf, pattern,
                                                  false, false,
-                                                 "es.stxnamespace::pg_catalog.regnamespace::text", "es.stxname",
+                                                 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text", "es.stxname",
                                                  NULL, "pg_catalog.pg_statistics_obj_is_visible(es.oid)");
 
        appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");