mirror of
https://github.com/postgres/postgres.git
synced 2025-07-21 16:02:15 +03:00
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
This commit is contained in:
@ -4011,14 +4011,18 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
|
|||||||
bool showSeq = strchr(tabtypes, 's') != NULL;
|
bool showSeq = strchr(tabtypes, 's') != NULL;
|
||||||
bool showForeign = strchr(tabtypes, 'E') != NULL;
|
bool showForeign = strchr(tabtypes, 'E') != NULL;
|
||||||
|
|
||||||
|
int ntypes;
|
||||||
PQExpBufferData buf;
|
PQExpBufferData buf;
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
printQueryOpt myopt = pset.popt;
|
printQueryOpt myopt = pset.popt;
|
||||||
int cols_so_far;
|
int cols_so_far;
|
||||||
bool translate_columns[] = {false, false, true, false, false, false, false, false, false};
|
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) */
|
/* Count the number of explicitly-requested relation types */
|
||||||
if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
|
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;
|
showTables = showViews = showMatViews = showSeq = showForeign = true;
|
||||||
|
|
||||||
initPQExpBuffer(&buf);
|
initPQExpBuffer(&buf);
|
||||||
@ -4169,14 +4173,63 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
|
|||||||
if (PQntuples(res) == 0 && !pset.quiet)
|
if (PQntuples(res) == 0 && !pset.quiet)
|
||||||
{
|
{
|
||||||
if (pattern)
|
if (pattern)
|
||||||
pg_log_error("Did not find any relation named \"%s\".",
|
{
|
||||||
|
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);
|
pattern);
|
||||||
else
|
|
||||||
pg_log_error("Did not find any relations.");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
myopt.title = _("List of 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 =
|
||||||
|
(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_header = true;
|
||||||
myopt.translate_columns = translate_columns;
|
myopt.translate_columns = translate_columns;
|
||||||
myopt.n_translate_columns = lengthof(translate_columns);
|
myopt.n_translate_columns = lengthof(translate_columns);
|
||||||
|
@ -153,4 +153,11 @@ void pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
|
|||||||
exit(1); \
|
exit(1); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use these variants for "can't happen" cases, if it seems translating their
|
||||||
|
* messages would be a waste of effort.
|
||||||
|
*/
|
||||||
|
#define pg_log_error_internal(...) pg_log_error(__VA_ARGS__)
|
||||||
|
#define pg_fatal_internal(...) pg_fatal(__VA_ARGS__)
|
||||||
|
|
||||||
#endif /* COMMON_LOGGING_H */
|
#endif /* COMMON_LOGGING_H */
|
||||||
|
@ -116,7 +116,7 @@ FROM pg_type JOIN pg_class c ON typrelid = c.oid WHERE typname = 'deptest_t';
|
|||||||
RESET SESSION AUTHORIZATION;
|
RESET SESSION AUTHORIZATION;
|
||||||
REASSIGN OWNED BY regress_dep_user1 TO regress_dep_user2;
|
REASSIGN OWNED BY regress_dep_user1 TO regress_dep_user2;
|
||||||
\dt deptest
|
\dt deptest
|
||||||
List of relations
|
List of tables
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+---------+-------+-------------------
|
--------+---------+-------+-------------------
|
||||||
public | deptest | table | regress_dep_user2
|
public | deptest | table | regress_dep_user2
|
||||||
|
@ -3027,7 +3027,7 @@ Access method: heap
|
|||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
\dt+
|
\dt+
|
||||||
List of relations
|
List of tables
|
||||||
Schema | Name | Type | Owner | Persistence | Access method | Size | Description
|
Schema | Name | Type | Owner | Persistence | Access method | Size | Description
|
||||||
-----------------+---------------+-------+----------------------+-------------+---------------+---------+-------------
|
-----------------+---------------+-------+----------------------+-------------+---------------+---------+-------------
|
||||||
tableam_display | tbl_heap | table | regress_display_role | permanent | heap | 0 bytes |
|
tableam_display | tbl_heap | table | regress_display_role | permanent | heap | 0 bytes |
|
||||||
@ -3035,7 +3035,7 @@ Access method: heap
|
|||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
\dm+
|
\dm+
|
||||||
List of relations
|
List of materialized views
|
||||||
Schema | Name | Type | Owner | Persistence | Access method | Size | Description
|
Schema | Name | Type | Owner | Persistence | Access method | Size | Description
|
||||||
-----------------+--------------------+-------------------+----------------------+-------------+---------------+---------+-------------
|
-----------------+--------------------+-------------------+----------------------+-------------+---------------+---------+-------------
|
||||||
tableam_display | mat_view_heap_psql | materialized view | regress_display_role | permanent | heap_psql | 0 bytes |
|
tableam_display | mat_view_heap_psql | materialized view | regress_display_role | permanent | heap_psql | 0 bytes |
|
||||||
@ -3043,7 +3043,7 @@ Access method: heap
|
|||||||
|
|
||||||
-- But not for views and sequences.
|
-- But not for views and sequences.
|
||||||
\dv+
|
\dv+
|
||||||
List of relations
|
List of views
|
||||||
Schema | Name | Type | Owner | Persistence | Size | Description
|
Schema | Name | Type | Owner | Persistence | Size | Description
|
||||||
-----------------+----------------+------+----------------------+-------------+---------+-------------
|
-----------------+----------------+------+----------------------+-------------+---------+-------------
|
||||||
tableam_display | view_heap_psql | view | regress_display_role | permanent | 0 bytes |
|
tableam_display | view_heap_psql | view | regress_display_role | permanent | 0 bytes |
|
||||||
@ -6244,7 +6244,7 @@ List of access methods
|
|||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\dt "no.such.table.relation"
|
\dt "no.such.table.relation"
|
||||||
List of relations
|
List of tables
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
@ -6316,31 +6316,31 @@ List of access methods
|
|||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\di "no.such.index.relation"
|
\di "no.such.index.relation"
|
||||||
List of relations
|
List of indexes
|
||||||
Schema | Name | Type | Owner | Table
|
Schema | Name | Type | Owner | Table
|
||||||
--------+------+------+-------+-------
|
--------+------+------+-------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\dm "no.such.materialized.view"
|
\dm "no.such.materialized.view"
|
||||||
List of relations
|
List of materialized views
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\ds "no.such.relation"
|
\ds "no.such.relation"
|
||||||
List of relations
|
List of sequences
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\dt "no.such.relation"
|
\dt "no.such.relation"
|
||||||
List of relations
|
List of tables
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\dv "no.such.relation"
|
\dv "no.such.relation"
|
||||||
List of relations
|
List of views
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
@ -6474,7 +6474,7 @@ List of schemas
|
|||||||
\dA "no.such.schema"."no.such.access.method"
|
\dA "no.such.schema"."no.such.access.method"
|
||||||
improper qualified name (too many dotted names): "no.such.schema"."no.such.access.method"
|
improper qualified name (too many dotted names): "no.such.schema"."no.such.access.method"
|
||||||
\dt "no.such.schema"."no.such.table.relation"
|
\dt "no.such.schema"."no.such.table.relation"
|
||||||
List of relations
|
List of tables
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
@ -6526,31 +6526,31 @@ improper qualified name (too many dotted names): "no.such.schema"."no.such.table
|
|||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\di "no.such.schema"."no.such.index.relation"
|
\di "no.such.schema"."no.such.index.relation"
|
||||||
List of relations
|
List of indexes
|
||||||
Schema | Name | Type | Owner | Table
|
Schema | Name | Type | Owner | Table
|
||||||
--------+------+------+-------+-------
|
--------+------+------+-------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\dm "no.such.schema"."no.such.materialized.view"
|
\dm "no.such.schema"."no.such.materialized.view"
|
||||||
List of relations
|
List of materialized views
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\ds "no.such.schema"."no.such.relation"
|
\ds "no.such.schema"."no.such.relation"
|
||||||
List of relations
|
List of sequences
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\dt "no.such.schema"."no.such.relation"
|
\dt "no.such.schema"."no.such.relation"
|
||||||
List of relations
|
List of tables
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\dv "no.such.schema"."no.such.relation"
|
\dv "no.such.schema"."no.such.relation"
|
||||||
List of relations
|
List of views
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
@ -6641,7 +6641,7 @@ improper qualified name (too many dotted names): "no.such.schema"."no.such.insta
|
|||||||
improper qualified name (too many dotted names): "no.such.schema"."no.such.event.trigger"
|
improper qualified name (too many dotted names): "no.such.schema"."no.such.event.trigger"
|
||||||
-- again, but with current database and dotted schema qualifications.
|
-- again, but with current database and dotted schema qualifications.
|
||||||
\dt regression."no.such.schema"."no.such.table.relation"
|
\dt regression."no.such.schema"."no.such.table.relation"
|
||||||
List of relations
|
List of tables
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
@ -6677,31 +6677,31 @@ improper qualified name (too many dotted names): "no.such.schema"."no.such.event
|
|||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\di regression."no.such.schema"."no.such.index.relation"
|
\di regression."no.such.schema"."no.such.index.relation"
|
||||||
List of relations
|
List of indexes
|
||||||
Schema | Name | Type | Owner | Table
|
Schema | Name | Type | Owner | Table
|
||||||
--------+------+------+-------+-------
|
--------+------+------+-------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\dm regression."no.such.schema"."no.such.materialized.view"
|
\dm regression."no.such.schema"."no.such.materialized.view"
|
||||||
List of relations
|
List of materialized views
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\ds regression."no.such.schema"."no.such.relation"
|
\ds regression."no.such.schema"."no.such.relation"
|
||||||
List of relations
|
List of sequences
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\dt regression."no.such.schema"."no.such.relation"
|
\dt regression."no.such.schema"."no.such.relation"
|
||||||
List of relations
|
List of tables
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
\dv regression."no.such.schema"."no.such.relation"
|
\dv regression."no.such.schema"."no.such.relation"
|
||||||
List of relations
|
List of views
|
||||||
Schema | Name | Type | Owner
|
Schema | Name | Type | Owner
|
||||||
--------+------+------+-------
|
--------+------+------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
Reference in New Issue
Block a user