Skip to content

Commit b681a87

Browse files
committed
Make psql's \d+ show reloptions for all relkinds.
Formerly it would only show them for relkinds 'r' and 'f' (plain tables and foreign tables). However, as of 9.2, views can also have reloptions, namely security_barrier. The relkind restriction seems pointless and not at all future-proof, so just print reloptions whenever there are any. In passing, make some cosmetic improvements to the code that pulls the "tableinfo" fields out of the PGresult. Noted and patched by Dean Rasheed, with adjustment for all relkinds by me.
1 parent 2d03874 commit b681a87

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/bin/psql/describe.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,13 +1237,14 @@ describeOneTableDetails(const char *schemaname,
12371237
tableinfo.hastriggers = strcmp(PQgetvalue(res, 0, 4), "t") == 0;
12381238
tableinfo.hasoids = strcmp(PQgetvalue(res, 0, 5), "t") == 0;
12391239
tableinfo.reloptions = (pset.sversion >= 80200) ?
1240-
strdup(PQgetvalue(res, 0, 6)) : 0;
1240+
strdup(PQgetvalue(res, 0, 6)) : NULL;
12411241
tableinfo.tablespace = (pset.sversion >= 80000) ?
12421242
atooid(PQgetvalue(res, 0, 7)) : 0;
1243-
tableinfo.reloftype = (pset.sversion >= 90000 && strcmp(PQgetvalue(res, 0, 8), "") != 0) ?
1244-
strdup(PQgetvalue(res, 0, 8)) : 0;
1245-
tableinfo.relpersistence = (pset.sversion >= 90100 && strcmp(PQgetvalue(res, 0, 9), "") != 0) ?
1246-
PQgetvalue(res, 0, 9)[0] : 0;
1243+
tableinfo.reloftype = (pset.sversion >= 90000 &&
1244+
strcmp(PQgetvalue(res, 0, 8), "") != 0) ?
1245+
strdup(PQgetvalue(res, 0, 8)) : NULL;
1246+
tableinfo.relpersistence = (pset.sversion >= 90100) ?
1247+
*(PQgetvalue(res, 0, 9)) : 0;
12471248
PQclear(res);
12481249
res = NULL;
12491250

@@ -2224,33 +2225,31 @@ describeOneTableDetails(const char *schemaname,
22242225
printTableAddFooter(&cont, buf.data);
22252226
}
22262227

2227-
/* OIDs and options */
2228+
/* OIDs, if verbose */
22282229
if (verbose)
22292230
{
22302231
const char *s = _("Has OIDs");
22312232

22322233
printfPQExpBuffer(&buf, "%s: %s", s,
22332234
(tableinfo.hasoids ? _("yes") : _("no")));
22342235
printTableAddFooter(&cont, buf.data);
2235-
2236-
/* print reloptions */
2237-
if (pset.sversion >= 80200)
2238-
{
2239-
if (tableinfo.reloptions && tableinfo.reloptions[0] != '\0')
2240-
{
2241-
const char *t = _("Options");
2242-
2243-
printfPQExpBuffer(&buf, "%s: %s", t,
2244-
tableinfo.reloptions);
2245-
printTableAddFooter(&cont, buf.data);
2246-
}
2247-
}
22482236
}
22492237

2238+
/* Tablespace info */
22502239
add_tablespace_footer(&cont, tableinfo.relkind, tableinfo.tablespace,
22512240
true);
22522241
}
22532242

2243+
/* reloptions, if verbose */
2244+
if (verbose &&
2245+
tableinfo.reloptions && tableinfo.reloptions[0] != '\0')
2246+
{
2247+
const char *t = _("Options");
2248+
2249+
printfPQExpBuffer(&buf, "%s: %s", t, tableinfo.reloptions);
2250+
printTableAddFooter(&cont, buf.data);
2251+
}
2252+
22542253
printTable(&cont, pset.queryFout, pset.logfile);
22552254
printTableCleanup(&cont);
22562255

0 commit comments

Comments
 (0)