Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7d80441

Browse files
committed
Allow psql's \dt and \di to show TOAST tables and their indexes.
Formerly, TOAST objects were unconditionally suppressed, but since \d is able to print them it's not very clear why these variants should not. Instead, use the same rules as for system catalogs: they can be seen if you write the 'S' modifier or a table name pattern. (In practice, since hardly anybody would keep pg_toast in their search_path, it's really down to whether you use a pattern that can match pg_toast.*.) No docs change seems necessary because the docs already say that this happens for "system objects"; we're just classifying TOAST tables as being that. Justin Pryzby, reviewed by Laurenz Albe Discussion: https://postgr.es/m/20201130165436.GX24052@telsasoft.com
1 parent bf8a662 commit 7d80441

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

src/bin/psql/describe.c

+9-18
Original file line numberDiff line numberDiff line change
@@ -3718,6 +3718,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
37183718
" WHEN " CppAsString2(RELKIND_INDEX) " THEN '%s'"
37193719
" WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
37203720
" WHEN 's' THEN '%s'"
3721+
" WHEN " CppAsString2(RELKIND_TOASTVALUE) " THEN '%s'"
37213722
" WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
37223723
" WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
37233724
" WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
@@ -3731,6 +3732,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
37313732
gettext_noop("index"),
37323733
gettext_noop("sequence"),
37333734
gettext_noop("special"),
3735+
gettext_noop("TOAST table"),
37343736
gettext_noop("foreign table"),
37353737
gettext_noop("partitioned table"),
37363738
gettext_noop("partitioned index"),
@@ -3813,8 +3815,13 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
38133815

38143816
appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
38153817
if (showTables)
3818+
{
38163819
appendPQExpBufferStr(&buf, CppAsString2(RELKIND_RELATION) ","
38173820
CppAsString2(RELKIND_PARTITIONED_TABLE) ",");
3821+
/* with 'S' or a pattern, allow 't' to match TOAST tables too */
3822+
if (showSystem || pattern)
3823+
appendPQExpBufferStr(&buf, CppAsString2(RELKIND_TOASTVALUE) ",");
3824+
}
38183825
if (showViews)
38193826
appendPQExpBufferStr(&buf, CppAsString2(RELKIND_VIEW) ",");
38203827
if (showMatViews)
@@ -3834,17 +3841,9 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
38343841

38353842
if (!showSystem && !pattern)
38363843
appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3844+
" AND n.nspname !~ '^pg_toast'\n"
38373845
" AND n.nspname <> 'information_schema'\n");
38383846

3839-
/*
3840-
* TOAST objects are suppressed unconditionally. Since we don't provide
3841-
* any way to select RELKIND_TOASTVALUE above, we would never show toast
3842-
* tables in any case; it seems a bit confusing to allow their indexes to
3843-
* be shown. Use plain \d if you really need to look at a TOAST
3844-
* table/index.
3845-
*/
3846-
appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
3847-
38483847
processSQLNamePattern(pset.db, &buf, pattern, true, false,
38493848
"n.nspname", "c.relname", NULL,
38503849
"pg_catalog.pg_table_is_visible(c.oid)");
@@ -4057,17 +4056,9 @@ listPartitionedTables(const char *reltypes, const char *pattern, bool verbose)
40574056

40584057
if (!pattern)
40594058
appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4059+
" AND n.nspname !~ '^pg_toast'\n"
40604060
" AND n.nspname <> 'information_schema'\n");
40614061

4062-
/*
4063-
* TOAST objects are suppressed unconditionally. Since we don't provide
4064-
* any way to select RELKIND_TOASTVALUE above, we would never show toast
4065-
* tables in any case; it seems a bit confusing to allow their indexes to
4066-
* be shown. Use plain \d if you really need to look at a TOAST
4067-
* table/index.
4068-
*/
4069-
appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
4070-
40714062
processSQLNamePattern(pset.db, &buf, pattern, true, false,
40724063
"n.nspname", "c.relname", NULL,
40734064
"pg_catalog.pg_table_is_visible(c.oid)");

src/test/regress/expected/psql.out

+14
Original file line numberDiff line numberDiff line change
@@ -4895,6 +4895,20 @@ Owning table: "pg_catalog.pg_statistic"
48954895
Indexes:
48964896
"pg_toast_2619_index" PRIMARY KEY, btree (chunk_id, chunk_seq)
48974897

4898+
\dt pg_toast.pg_toast_2619
4899+
List of relations
4900+
Schema | Name | Type | Owner
4901+
----------+---------------+-------------+----------
4902+
pg_toast | pg_toast_2619 | TOAST table | postgres
4903+
(1 row)
4904+
4905+
\di pg_toast.pg_toast_2619_index
4906+
List of relations
4907+
Schema | Name | Type | Owner | Table
4908+
----------+---------------------+-------+----------+---------------
4909+
pg_toast | pg_toast_2619_index | index | postgres | pg_toast_2619
4910+
(1 row)
4911+
48984912
-- check printing info about access methods
48994913
\dA
49004914
List of access methods

src/test/regress/sql/psql.sql

+2
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,8 @@ drop role regress_partitioning_role;
12101210

12111211
-- \d on toast table (use pg_statistic's toast table, which has a known name)
12121212
\d pg_toast.pg_toast_2619
1213+
\dt pg_toast.pg_toast_2619
1214+
\di pg_toast.pg_toast_2619_index
12131215

12141216
-- check printing info about access methods
12151217
\dA

0 commit comments

Comments
 (0)