Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita14707d

Browse files
committed
Show more-intuitive titles for psql commands \dt, \di, etc.
If exactly one relation type is requested in a command of the \dtisvfamily, say "tables", "indexes", etc instead of "relations". Thisshould cover the majority of actual uses, without creating a hugenumber of new translatable strings. The error messages for nomatching relations are adjusted as well.In passing, invent "pg_log_error_internal()" to be used for frontenderror messages that don't seem to need translation, analogously toerrmsg_internal() in the backend. The implementation is a bit cheesy,being just a macro to prevent xgettext from recognizing a triggerkeyword. This won't avoid a useless gettext lookup cycle at runtime--- but surely we don't care about an extra microsecond or two inwhat'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
1 parentee4667f commita14707d

File tree

4 files changed

+88
-28
lines changed

4 files changed

+88
-28
lines changed

‎src/bin/psql/describe.c

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4011,14 +4011,18 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
40114011
boolshowSeq=strchr(tabtypes,'s')!=NULL;
40124012
boolshowForeign=strchr(tabtypes,'E')!=NULL;
40134013

4014+
intntypes;
40144015
PQExpBufferDatabuf;
40154016
PGresult*res;
40164017
printQueryOptmyopt=pset.popt;
40174018
intcols_so_far;
40184019
booltranslate_columns[]= {false, false, true, false, false, false, false, false, false};
40194020

4020-
/* If tabtypes is empty, we default to \dtvmsE (but see also command.c) */
4021-
if (!(showTables||showIndexes||showViews||showMatViews||showSeq||showForeign))
4021+
/* Count the number of explicitly-requested relation types */
4022+
ntypes=showTables+showIndexes+showViews+showMatViews+
4023+
showSeq+showForeign;
4024+
/* If none, we default to \dtvmsE (but see also command.c) */
4025+
if (ntypes==0)
40224026
showTables=showViews=showMatViews=showSeq=showForeign= true;
40234027

40244028
initPQExpBuffer(&buf);
@@ -4169,14 +4173,63 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
41694173
if (PQntuples(res)==0&& !pset.quiet)
41704174
{
41714175
if (pattern)
4172-
pg_log_error("Did not find any relation named \"%s\".",
4173-
pattern);
4176+
{
4177+
if (ntypes!=1)
4178+
pg_log_error("Did not find any relations named \"%s\".",
4179+
pattern);
4180+
elseif (showTables)
4181+
pg_log_error("Did not find any tables named \"%s\".",
4182+
pattern);
4183+
elseif (showIndexes)
4184+
pg_log_error("Did not find any indexes named \"%s\".",
4185+
pattern);
4186+
elseif (showViews)
4187+
pg_log_error("Did not find any views named \"%s\".",
4188+
pattern);
4189+
elseif (showMatViews)
4190+
pg_log_error("Did not find any materialized views named \"%s\".",
4191+
pattern);
4192+
elseif (showSeq)
4193+
pg_log_error("Did not find any sequences named \"%s\".",
4194+
pattern);
4195+
elseif (showForeign)
4196+
pg_log_error("Did not find any foreign tables named \"%s\".",
4197+
pattern);
4198+
else/* should not get here */
4199+
pg_log_error_internal("Did not find any ??? named \"%s\".",
4200+
pattern);
4201+
}
41744202
else
4175-
pg_log_error("Did not find any relations.");
4203+
{
4204+
if (ntypes!=1)
4205+
pg_log_error("Did not find any relations.");
4206+
elseif (showTables)
4207+
pg_log_error("Did not find any tables.");
4208+
elseif (showIndexes)
4209+
pg_log_error("Did not find any indexes.");
4210+
elseif (showViews)
4211+
pg_log_error("Did not find any views.");
4212+
elseif (showMatViews)
4213+
pg_log_error("Did not find any materialized views.");
4214+
elseif (showSeq)
4215+
pg_log_error("Did not find any sequences.");
4216+
elseif (showForeign)
4217+
pg_log_error("Did not find any foreign tables.");
4218+
else/* should not get here */
4219+
pg_log_error_internal("Did not find any ??? relations.");
4220+
}
41764221
}
41774222
else
41784223
{
4179-
myopt.title=_("List of relations");
4224+
myopt.title=
4225+
(ntypes!=1) ?_("List of relations") :
4226+
(showTables) ?_("List of tables") :
4227+
(showIndexes) ?_("List of indexes") :
4228+
(showViews) ?_("List of views") :
4229+
(showMatViews) ?_("List of materialized views") :
4230+
(showSeq) ?_("List of sequences") :
4231+
(showForeign) ?_("List of foreign tables") :
4232+
"List of ???";/* should not get here */
41804233
myopt.translate_header= true;
41814234
myopt.translate_columns=translate_columns;
41824235
myopt.n_translate_columns=lengthof(translate_columns);

‎src/include/common/logging.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,11 @@ voidpg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
153153
exit(1); \
154154
} while(0)
155155

156+
/*
157+
* Use these variants for "can't happen" cases, if it seems translating their
158+
* messages would be a waste of effort.
159+
*/
160+
#definepg_log_error_internal(...) pg_log_error(__VA_ARGS__)
161+
#definepg_fatal_internal(...) pg_fatal(__VA_ARGS__)
162+
156163
#endif/* COMMON_LOGGING_H */

‎src/test/regress/expected/dependency.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ FROM pg_type JOIN pg_class c ON typrelid = c.oid WHERE typname = 'deptest_t';
116116
RESET SESSION AUTHORIZATION;
117117
REASSIGN OWNED BY regress_dep_user1 TO regress_dep_user2;
118118
\dt deptest
119-
List ofrelations
119+
List oftables
120120
Schema | Name | Type | Owner
121121
--------+---------+-------+-------------------
122122
public | deptest | table | regress_dep_user2

‎src/test/regress/expected/psql.out

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,23 +3027,23 @@ Access method: heap
30273027
(4 rows)
30283028

30293029
\dt+
3030-
List ofrelations
3030+
List oftables
30313031
Schema | Name | Type | Owner | Persistence | Access method | Size | Description
30323032
-----------------+---------------+-------+----------------------+-------------+---------------+---------+-------------
30333033
tableam_display | tbl_heap | table | regress_display_role | permanent | heap | 0 bytes |
30343034
tableam_display | tbl_heap_psql | table | regress_display_role | permanent | heap_psql | 0 bytes |
30353035
(2 rows)
30363036

30373037
\dm+
3038-
List ofrelations
3038+
List ofmaterialized views
30393039
Schema | Name | Type | Owner | Persistence | Access method | Size | Description
30403040
-----------------+--------------------+-------------------+----------------------+-------------+---------------+---------+-------------
30413041
tableam_display | mat_view_heap_psql | materialized view | regress_display_role | permanent | heap_psql | 0 bytes |
30423042
(1 row)
30433043

30443044
-- But not for views and sequences.
30453045
\dv+
3046-
List ofrelations
3046+
List ofviews
30473047
Schema | Name | Type | Owner | Persistence | Size | Description
30483048
-----------------+----------------+------+----------------------+-------------+---------+-------------
30493049
tableam_display | view_heap_psql | view | regress_display_role | permanent | 0 bytes |
@@ -6244,7 +6244,7 @@ List of access methods
62446244
(0 rows)
62456245

62466246
\dt "no.such.table.relation"
6247-
List ofrelations
6247+
List oftables
62486248
Schema | Name | Type | Owner
62496249
--------+------+------+-------
62506250
(0 rows)
@@ -6316,31 +6316,31 @@ List of access methods
63166316
(0 rows)
63176317

63186318
\di "no.such.index.relation"
6319-
List ofrelations
6319+
List ofindexes
63206320
Schema | Name | Type | Owner | Table
63216321
--------+------+------+-------+-------
63226322
(0 rows)
63236323

63246324
\dm "no.such.materialized.view"
6325-
List ofrelations
6325+
List ofmaterialized views
63266326
Schema | Name | Type | Owner
63276327
--------+------+------+-------
63286328
(0 rows)
63296329

63306330
\ds "no.such.relation"
6331-
List ofrelations
6331+
List ofsequences
63326332
Schema | Name | Type | Owner
63336333
--------+------+------+-------
63346334
(0 rows)
63356335

63366336
\dt "no.such.relation"
6337-
List ofrelations
6337+
List oftables
63386338
Schema | Name | Type | Owner
63396339
--------+------+------+-------
63406340
(0 rows)
63416341

63426342
\dv "no.such.relation"
6343-
List ofrelations
6343+
List ofviews
63446344
Schema | Name | Type | Owner
63456345
--------+------+------+-------
63466346
(0 rows)
@@ -6474,7 +6474,7 @@ List of schemas
64746474
\dA "no.such.schema"."no.such.access.method"
64756475
improper qualified name (too many dotted names): "no.such.schema"."no.such.access.method"
64766476
\dt "no.such.schema"."no.such.table.relation"
6477-
List ofrelations
6477+
List oftables
64786478
Schema | Name | Type | Owner
64796479
--------+------+------+-------
64806480
(0 rows)
@@ -6526,31 +6526,31 @@ improper qualified name (too many dotted names): "no.such.schema"."no.such.table
65266526
(0 rows)
65276527

65286528
\di "no.such.schema"."no.such.index.relation"
6529-
List ofrelations
6529+
List ofindexes
65306530
Schema | Name | Type | Owner | Table
65316531
--------+------+------+-------+-------
65326532
(0 rows)
65336533

65346534
\dm "no.such.schema"."no.such.materialized.view"
6535-
List ofrelations
6535+
List ofmaterialized views
65366536
Schema | Name | Type | Owner
65376537
--------+------+------+-------
65386538
(0 rows)
65396539

65406540
\ds "no.such.schema"."no.such.relation"
6541-
List ofrelations
6541+
List ofsequences
65426542
Schema | Name | Type | Owner
65436543
--------+------+------+-------
65446544
(0 rows)
65456545

65466546
\dt "no.such.schema"."no.such.relation"
6547-
List ofrelations
6547+
List oftables
65486548
Schema | Name | Type | Owner
65496549
--------+------+------+-------
65506550
(0 rows)
65516551

65526552
\dv "no.such.schema"."no.such.relation"
6553-
List ofrelations
6553+
List ofviews
65546554
Schema | Name | Type | Owner
65556555
--------+------+------+-------
65566556
(0 rows)
@@ -6641,7 +6641,7 @@ improper qualified name (too many dotted names): "no.such.schema"."no.such.insta
66416641
improper qualified name (too many dotted names): "no.such.schema"."no.such.event.trigger"
66426642
-- again, but with current database and dotted schema qualifications.
66436643
\dt regression."no.such.schema"."no.such.table.relation"
6644-
List ofrelations
6644+
List oftables
66456645
Schema | Name | Type | Owner
66466646
--------+------+------+-------
66476647
(0 rows)
@@ -6677,31 +6677,31 @@ improper qualified name (too many dotted names): "no.such.schema"."no.such.event
66776677
(0 rows)
66786678

66796679
\di regression."no.such.schema"."no.such.index.relation"
6680-
List ofrelations
6680+
List ofindexes
66816681
Schema | Name | Type | Owner | Table
66826682
--------+------+------+-------+-------
66836683
(0 rows)
66846684

66856685
\dm regression."no.such.schema"."no.such.materialized.view"
6686-
List ofrelations
6686+
List ofmaterialized views
66876687
Schema | Name | Type | Owner
66886688
--------+------+------+-------
66896689
(0 rows)
66906690

66916691
\ds regression."no.such.schema"."no.such.relation"
6692-
List ofrelations
6692+
List ofsequences
66936693
Schema | Name | Type | Owner
66946694
--------+------+------+-------
66956695
(0 rows)
66966696

66976697
\dt regression."no.such.schema"."no.such.relation"
6698-
List ofrelations
6698+
List oftables
66996699
Schema | Name | Type | Owner
67006700
--------+------+------+-------
67016701
(0 rows)
67026702

67036703
\dv regression."no.such.schema"."no.such.relation"
6704-
List ofrelations
6704+
List ofviews
67056705
Schema | Name | Type | Owner
67066706
--------+------+------+-------
67076707
(0 rows)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp