Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c18f3f

Browse files
committed
Only display column comments for relkinds that support them.
Josh Kupershmidt, with minor modifications by me.
1 parent c80be8a commit 8c18f3f

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/bin/psql/describe.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,17 @@ describeOneTableDetails(const char *schemaname,
12961296
if (tableinfo.relkind == 'i')
12971297
appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_indexdef(a.attrelid, a.attnum, TRUE) AS indexdef");
12981298
if (verbose)
1299-
appendPQExpBuffer(&buf, ",\n a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)");
1299+
{
1300+
appendPQExpBuffer(&buf, ",\n a.attstorage");
1301+
/*
1302+
* In 9.0+, we have column comments for: relations, views, composite
1303+
* types, and foreign tables (c.f. CommentObject() in comment.c).
1304+
*/
1305+
if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
1306+
tableinfo.relkind == 'f' || tableinfo.relkind == 'c')
1307+
appendPQExpBuffer(&buf, ", pg_catalog.col_description(a.attrelid, a.attnum)");
1308+
}
1309+
13001310
appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a");
13011311
appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
13021312
appendPQExpBuffer(&buf, "\nORDER BY a.attnum;");
@@ -1379,7 +1389,10 @@ describeOneTableDetails(const char *schemaname,
13791389
if (verbose)
13801390
{
13811391
headers[cols++] = gettext_noop("Storage");
1382-
headers[cols++] = gettext_noop("Description");
1392+
/* Column comments, if the relkind supports this feature. */
1393+
if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
1394+
tableinfo.relkind == 'c' || tableinfo.relkind == 'f')
1395+
headers[cols++] = gettext_noop("Description");
13831396
}
13841397

13851398
printTableInit(&cont, &myopt, title.data, cols, numrows);
@@ -1471,8 +1484,11 @@ describeOneTableDetails(const char *schemaname,
14711484
(storage[0] == 'e' ? "external" :
14721485
"???")))),
14731486
false, false);
1474-
printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 1),
1475-
false, false);
1487+
/* Column comments, if the relkind supports this feature. */
1488+
if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
1489+
tableinfo.relkind == 'c' || tableinfo.relkind == 'f')
1490+
printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 1),
1491+
false, false);
14761492
}
14771493
}
14781494

0 commit comments

Comments
 (0)