Skip to content

Commit

Permalink
Clean up psql/describe.c's messy query for extended stats.
Browse files Browse the repository at this point in the history
Remove unnecessary casts, safely schema-qualify the ones that remain,
lose an unnecessary level of sub-SELECT, reformat for tidiness.
  • Loading branch information
tglsfdc committed Apr 6, 2017
1 parent e6c9a5a commit 20c95f2
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/bin/psql/describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2343,15 +2343,18 @@ describeOneTableDetails(const char *schemaname,
if (pset.sversion >= 100000)
{
printfPQExpBuffer(&buf,
"SELECT oid, stanamespace::regnamespace AS nsp, staname, stakeys,\n"
" (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname::text),', ') \n"
" FROM ((SELECT pg_catalog.unnest(stakeys) AS attnum) s\n"
" JOIN pg_catalog.pg_attribute a ON (starelid = a.attrelid AND\n"
"a.attnum = s.attnum AND not attisdropped))) AS columns,\n"
" (staenabled::char[] @> '{d}'::char[]) AS ndist_enabled,\n"
" (staenabled::char[] @> '{f}'::char[]) AS deps_enabled\n"
"FROM pg_catalog.pg_statistic_ext stat WHERE starelid = '%s'\n"
"ORDER BY 1;",
"SELECT oid, "
"stanamespace::pg_catalog.regnamespace AS nsp, "
"staname, stakeys,\n"
" (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
" FROM pg_catalog.unnest(stakeys) s(attnum)\n"
" JOIN pg_catalog.pg_attribute a ON (starelid = a.attrelid AND\n"
" a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
" (staenabled @> '{d}') AS ndist_enabled,\n"
" (staenabled @> '{f}') AS deps_enabled\n"
"FROM pg_catalog.pg_statistic_ext stat "
"WHERE starelid = '%s'\n"
"ORDER BY 1;",
oid);

result = PSQLexec(buf.data);
Expand Down

0 comments on commit 20c95f2

Please sign in to comment.