From 38847cfdbf712bc9ccbbca68a26b3f7672a783e5 Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Mon, 3 Feb 2025 16:20:18 -0500 Subject: [PATCH] Show more intuitive titles for psql commands \dt \di \dv \dm \ds and \dE This applies to the modified versions as well e.g. \dt+ \dtS+ Rather than say "List of relations", if someone has entered in a \di, we say "List of indexes" Per complaint on the bugs list on Jan 29, 2025 from xpusostomos@gmail.com --- src/bin/psql/describe.c | 53 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index aa4363b200..c442d1a565 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -4011,14 +4011,17 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys bool showSeq = strchr(tabtypes, 's') != NULL; bool showForeign = strchr(tabtypes, 'E') != NULL; + int ntypes = showTables + showIndexes + showViews + showMatViews + showSeq + showForeign; + PQExpBufferData buf; + PQExpBufferData title; PGresult *res; printQueryOpt myopt = pset.popt; int cols_so_far; bool translate_columns[] = {false, false, true, false, false, false, false, false, false}; /* If tabtypes is empty, we default to \dtvmsE (but see also command.c) */ - if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign)) + if (ntypes < 1) showTables = showViews = showMatViews = showSeq = showForeign = true; initPQExpBuffer(&buf); @@ -4169,14 +4172,54 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys if (PQntuples(res) == 0 && !pset.quiet) { if (pattern) - pg_log_error("Did not find any relation named \"%s\".", - pattern); + { + if (ntypes == 1 && showTables) + pg_log_error("Did not find any tables named \"%s\".", pattern); + else if (ntypes == 1 && showIndexes) + pg_log_error("Did not find any indexes named \"%s\".", pattern); + else if (ntypes == 1 && showViews) + pg_log_error("Did not find any views named \"%s\".", pattern); + else if (ntypes == 1 && showMatViews) + pg_log_error("Did not find any materialized views named \"%s\".", pattern); + else if (ntypes == 1 && showSeq) + pg_log_error("Did not find any sequences named \"%s\".", pattern); + else if (ntypes == 1 && showForeign) + pg_log_error("Did not find any foreign tables named \"%s\".", pattern); + else + pg_log_error("Did not find any relations named \"%s\".", pattern); + + } else - pg_log_error("Did not find any relations."); + { + if (ntypes == 1 && showTables) + pg_log_error("Did not find any tables."); + else if (ntypes == 1 && showIndexes) + pg_log_error("Did not find any indexes."); + else if (ntypes == 1 && showViews) + pg_log_error("Did not find any views."); + else if (ntypes == 1 && showMatViews) + pg_log_error("Did not find any materialized views."); + else if (ntypes == 1 && showSeq) + pg_log_error("Did not find any sequences."); + else if (ntypes == 1 && showForeign) + pg_log_error("Did not find any foreign tables."); + else + pg_log_error("Did not find any relations."); + } } else { - myopt.title = _("List of relations"); + initPQExpBuffer(&title); + printfPQExpBuffer(&title, + (ntypes == 1 && showTables) ? _("List of tables") : + (ntypes == 1 && showIndexes) ? _("List of indexes") : + (ntypes == 1 && showViews) ? _("List of views") : + (ntypes == 1 && showMatViews) ? _("List of materialized views") : + (ntypes == 1 && showSeq) ? _("List of sequences") : + (ntypes == 1 && showForeign) ? _("List of foreign tables") : + _("List of relations")); + + myopt.title = title.data; myopt.translate_header = true; myopt.translate_columns = translate_columns; myopt.n_translate_columns = lengthof(translate_columns); -- 2.30.2