diff options
author | Robert Haas <rhaas@postgresql.org> | 2011-07-26 09:52:31 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2011-07-26 09:52:31 -0400 |
commit | 8c18f3f0e15738633231b31d8937b2710b38975f (patch) | |
tree | 2a067ea7870786d583e44b450070b3a6072eff63 | |
parent | c80be8a816ac4bf8b910aaaec599c683804bcd77 (diff) | |
download | postgresql-8c18f3f0e15738633231b31d8937b2710b38975f.tar.gz postgresql-8c18f3f0e15738633231b31d8937b2710b38975f.zip |
Only display column comments for relkinds that support them.
Josh Kupershmidt, with minor modifications by me.
-rw-r--r-- | src/bin/psql/describe.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 682cf8a40f2..b50c5d647f6 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); } } |