From 8c18f3f0e15738633231b31d8937b2710b38975f Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 26 Jul 2011 09:52:31 -0400 Subject: [PATCH] Only display column comments for relkinds that support them. Josh Kupershmidt, with minor modifications by me. --- src/bin/psql/describe.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 682cf8a40f..b50c5d647f 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -1296,7 +1296,17 @@ describeOneTableDetails(const char *schemaname, if (tableinfo.relkind == 'i') appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_indexdef(a.attrelid, a.attnum, TRUE) AS indexdef"); if (verbose) - appendPQExpBuffer(&buf, ",\n a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)"); + { + appendPQExpBuffer(&buf, ",\n a.attstorage"); + /* + * In 9.0+, we have column comments for: relations, views, composite + * types, and foreign tables (c.f. CommentObject() in comment.c). + */ + if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' || + tableinfo.relkind == 'f' || tableinfo.relkind == 'c') + appendPQExpBuffer(&buf, ", pg_catalog.col_description(a.attrelid, a.attnum)"); + } + appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a"); appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid); appendPQExpBuffer(&buf, "\nORDER BY a.attnum;"); @@ -1379,7 +1389,10 @@ describeOneTableDetails(const char *schemaname, if (verbose) { headers[cols++] = gettext_noop("Storage"); - headers[cols++] = gettext_noop("Description"); + /* Column comments, if the relkind supports this feature. */ + if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' || + tableinfo.relkind == 'c' || tableinfo.relkind == 'f') + headers[cols++] = gettext_noop("Description"); } printTableInit(&cont, &myopt, title.data, cols, numrows); @@ -1471,8 +1484,11 @@ describeOneTableDetails(const char *schemaname, (storage[0] == 'e' ? "external" : "???")))), false, false); - printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 1), - false, false); + /* Column comments, if the relkind supports this feature. */ + if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' || + tableinfo.relkind == 'c' || tableinfo.relkind == 'f') + printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 1), + false, false); } } -- 2.40.0