From: Justin Pryzby Date: Tue, 30 Apr 2019 19:05:53 -0500 Subject: [PATCH v5] print table associated with given TOAST table --- src/bin/psql/describe.c | 28 ++++++++++++++++++++++++++++ src/test/regress/expected/psql.out | 10 ++++++++++ src/test/regress/sql/psql.sql | 3 +++ 3 files changed, 41 insertions(+) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 3ee9c82..13ed2e1 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -2153,6 +2153,34 @@ describeOneTableDetails(const char *schemaname, } } + /* print table associated with given TOAST table */ + if (tableinfo.relkind == RELKIND_TOASTVALUE) + { + PGresult *result = NULL; + printfPQExpBuffer(&buf, + "SELECT c.relnamespace::pg_catalog.regnamespace, c.relname FROM pg_catalog.pg_class c WHERE reltoastrelid = '%s'", + oid); + result = PSQLexec(buf.data); + if (!result) + { + goto error_return; + } + else if (PQntuples(result) != 1) + { + PQclear(result); + goto error_return; + } + else + { + char *schemaname = PQgetvalue(result, 0, 0); + char *relname = PQgetvalue(result, 0, 1); + appendPQExpBuffer(&tmpbuf, _("For table: \"%s.%s\""), + schemaname, relname); + printTableAddFooter(&cont, tmpbuf.data); + PQclear(result); + } + } + if (tableinfo.relkind == RELKIND_PARTITIONED_TABLE) { /* Get the partition key information */ diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out index 9021c80..5c8e439 100644 --- a/src/test/regress/expected/psql.out +++ b/src/test/regress/expected/psql.out @@ -4748,3 +4748,13 @@ drop schema testpart; set search_path to default; set role to default; drop role regress_partitioning_role; +-- slash dee on toast table: +\d pg_toast.pg_toast_2619 +TOAST table "pg_toast.pg_toast_2619" + Column | Type +------------+--------- + chunk_id | oid + chunk_seq | integer + chunk_data | bytea +For table: "pg_catalog.pg_statistic" + diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql index cefe41b..b4a232d 100644 --- a/src/test/regress/sql/psql.sql +++ b/src/test/regress/sql/psql.sql @@ -1131,3 +1131,6 @@ set search_path to default; set role to default; drop role regress_partitioning_role; + +-- slash dee on toast table: +\d pg_toast.pg_toast_2619 -- 2.7.4 --dkEUBIird37B8yKS Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v5-0002-make-d-pg_toast.foo-show-its-indices.patch"