@@ -1296,7 +1296,17 @@ describeOneTableDetails(const char *schemaname,
1296
1296
if (tableinfo .relkind == 'i' )
1297
1297
appendPQExpBuffer (& buf , ",\n pg_catalog.pg_get_indexdef(a.attrelid, a.attnum, TRUE) AS indexdef" );
1298
1298
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
+
1300
1310
appendPQExpBuffer (& buf , "\nFROM pg_catalog.pg_attribute a" );
1301
1311
appendPQExpBuffer (& buf , "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped" , oid );
1302
1312
appendPQExpBuffer (& buf , "\nORDER BY a.attnum;" );
@@ -1379,7 +1389,10 @@ describeOneTableDetails(const char *schemaname,
1379
1389
if (verbose )
1380
1390
{
1381
1391
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" );
1383
1396
}
1384
1397
1385
1398
printTableInit (& cont , & myopt , title .data , cols , numrows );
@@ -1471,8 +1484,11 @@ describeOneTableDetails(const char *schemaname,
1471
1484
(storage [0 ] == 'e' ? "external" :
1472
1485
"???" )))),
1473
1486
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);
1476
1492
}
1477
1493
}
1478
1494
0 commit comments