diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2025-02-05 12:45:58 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2025-02-05 12:45:58 -0500 |
commit | a14707da564e8c94bd123f0e3a75e194fd7ef56a (patch) | |
tree | ea70529d79886ed96a78abbf326857ce363d01b8 /src/bin/psql | |
parent | ee4667f0184d87a2e58822e6a9edad563fa164fd (diff) | |
download | postgresql-a14707da564e8c94bd123f0e3a75e194fd7ef56a.tar.gz postgresql-a14707da564e8c94bd123f0e3a75e194fd7ef56a.zip |
Show more-intuitive titles for psql commands \dt, \di, etc.
If exactly one relation type is requested in a command of the \dtisv
family, say "tables", "indexes", etc instead of "relations". This
should cover the majority of actual uses, without creating a huge
number of new translatable strings. The error messages for no
matching relations are adjusted as well.
In passing, invent "pg_log_error_internal()" to be used for frontend
error messages that don't seem to need translation, analogously to
errmsg_internal() in the backend. The implementation is a bit cheesy,
being just a macro to prevent xgettext from recognizing a trigger
keyword. This won't avoid a useless gettext lookup cycle at runtime
--- but surely we don't care about an extra microsecond or two in
what's supposed to be a can't-happen case. I (tgl) also made
"pg_fatal_internal()", though it's not used in this patch.
Author: Greg Sabino Mullane <htamfids@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAKAnmm+7o93fQV-RFkGaN1QnP-0D4d3JTykD+cLueqjDMKdfag@mail.gmail.com
Diffstat (limited to 'src/bin/psql')
-rw-r--r-- | src/bin/psql/describe.c | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index aa4363b200a..0312de7dcb7 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -4011,14 +4011,18 @@ 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; PQExpBufferData buf; 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)) + /* Count the number of explicitly-requested relation types */ + ntypes = showTables + showIndexes + showViews + showMatViews + + showSeq + showForeign; + /* If none, we default to \dtvmsE (but see also command.c) */ + if (ntypes == 0) showTables = showViews = showMatViews = showSeq = showForeign = true; initPQExpBuffer(&buf); @@ -4169,14 +4173,63 @@ 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) + pg_log_error("Did not find any relations named \"%s\".", + pattern); + else if (showTables) + pg_log_error("Did not find any tables named \"%s\".", + pattern); + else if (showIndexes) + pg_log_error("Did not find any indexes named \"%s\".", + pattern); + else if (showViews) + pg_log_error("Did not find any views named \"%s\".", + pattern); + else if (showMatViews) + pg_log_error("Did not find any materialized views named \"%s\".", + pattern); + else if (showSeq) + pg_log_error("Did not find any sequences named \"%s\".", + pattern); + else if (showForeign) + pg_log_error("Did not find any foreign tables named \"%s\".", + pattern); + else /* should not get here */ + pg_log_error_internal("Did not find any ??? named \"%s\".", + pattern); + } else - pg_log_error("Did not find any relations."); + { + if (ntypes != 1) + pg_log_error("Did not find any relations."); + else if (showTables) + pg_log_error("Did not find any tables."); + else if (showIndexes) + pg_log_error("Did not find any indexes."); + else if (showViews) + pg_log_error("Did not find any views."); + else if (showMatViews) + pg_log_error("Did not find any materialized views."); + else if (showSeq) + pg_log_error("Did not find any sequences."); + else if (showForeign) + pg_log_error("Did not find any foreign tables."); + else /* should not get here */ + pg_log_error_internal("Did not find any ??? relations."); + } } else { - myopt.title = _("List of relations"); + myopt.title = + (ntypes != 1) ? _("List of relations") : + (showTables) ? _("List of tables") : + (showIndexes) ? _("List of indexes") : + (showViews) ? _("List of views") : + (showMatViews) ? _("List of materialized views") : + (showSeq) ? _("List of sequences") : + (showForeign) ? _("List of foreign tables") : + "List of ???"; /* should not get here */ myopt.translate_header = true; myopt.translate_columns = translate_columns; myopt.n_translate_columns = lengthof(translate_columns); |