Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c1f3c04

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 7682c59 commit c1f3c04

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
@@ -1236,13 +1236,14 @@ describeOneTableDetails(const char *schemaname,
12361236
tableinfo.hastriggers = strcmp(PQgetvalue(res, 0, 4), "t") == 0;
12371237
tableinfo.hasoids = strcmp(PQgetvalue(res, 0, 5), "t") == 0;
12381238
tableinfo.reloptions = (pset.sversion >= 80200) ?
1239-
strdup(PQgetvalue(res, 0, 6)) : 0;
1239+
strdup(PQgetvalue(res, 0, 6)) : NULL;
12401240
tableinfo.tablespace = (pset.sversion >= 80000) ?
12411241
atooid(PQgetvalue(res, 0, 7)) : 0;
1242-
tableinfo.reloftype = (pset.sversion >= 90000 && strcmp(PQgetvalue(res, 0, 8), "") != 0) ?
1243-
strdup(PQgetvalue(res, 0, 8)) : 0;
1244-
tableinfo.relpersistence = (pset.sversion >= 90100 && strcmp(PQgetvalue(res, 0, 9), "") != 0) ?
1245-
PQgetvalue(res, 0, 9)[0] : 0;
1242+
tableinfo.reloftype = (pset.sversion >= 90000 &&
1243+
strcmp(PQgetvalue(res, 0, 8), "") != 0) ?
1244+
strdup(PQgetvalue(res, 0, 8)) : NULL;
1245+
tableinfo.relpersistence = (pset.sversion >= 90100) ?
1246+
*(PQgetvalue(res, 0, 9)) : 0;
12461247
PQclear(res);
12471248
res = NULL;
12481249

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

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

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

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

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

0 commit comments

Comments
 (0)