From de656c1f589264ed9d376fd5726714bb28a0224a Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Mon, 3 Feb 2025 14:27:49 -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 | 48 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index aa4363b200..24faf44e40 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -4012,6 +4012,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys bool showForeign = strchr(tabtypes, 'E') != NULL; PQExpBufferData buf; + PQExpBufferData title; PGresult *res; printQueryOpt myopt = pset.popt; int cols_so_far; @@ -4169,14 +4170,53 @@ 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 (strspn(tabtypes, "tS+") == strlen(tabtypes)) + pg_log_error("Did not find any tables named \"%s\".", pattern); + else if (strspn(tabtypes, "iS+") == strlen(tabtypes)) + pg_log_error("Did not find any indexes named \"%s\".", pattern); + else if (strspn(tabtypes, "vS+") == strlen(tabtypes)) + pg_log_error("Did not find any views named \"%s\".", pattern); + else if (strspn(tabtypes, "mS+") == strlen(tabtypes)) + pg_log_error("Did not find any materialized views named \"%s\".", pattern); + else if (strspn(tabtypes, "sS+") == strlen(tabtypes)) + pg_log_error("Did not find any sequences named \"%s\".", pattern); + else if (strspn(tabtypes, "ES+") == strlen(tabtypes)) + 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 (strspn(tabtypes, "tS+") == strlen(tabtypes)) + pg_log_error("Did not find any tables."); + else if (strspn(tabtypes, "iS+") == strlen(tabtypes)) + pg_log_error("Did not find any indexes."); + else if (strspn(tabtypes, "vS+") == strlen(tabtypes)) + pg_log_error("Did not find any views."); + else if (strspn(tabtypes, "mS+") == strlen(tabtypes)) + pg_log_error("Did not find any materialized views."); + else if (strspn(tabtypes, "sS+") == strlen(tabtypes)) + pg_log_error("Did not find any sequences."); + else if (strspn(tabtypes, "ES+") == strlen(tabtypes)) + 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, + (strspn(tabtypes, "tS+") == strlen(tabtypes)) ? _("List of tables") : + (strspn(tabtypes, "iS+") == strlen(tabtypes)) ? _("List of indexes") : + (strspn(tabtypes, "vS+") == strlen(tabtypes)) ? _("List of views") : + (strspn(tabtypes, "mS+") == strlen(tabtypes)) ? _("List of materialized view") : + (strspn(tabtypes, "sS+") == strlen(tabtypes)) ? _("List of sequences") : + (strspn(tabtypes, "ES+") == strlen(tabtypes)) ? _("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