psql_describe_am_v2.patch
application/octet-stream
Filename: psql_describe_am_v2.patch
Type: application/octet-stream
Part: 0
Patch
Format: unified
Series: patch v2
| File | + | − |
|---|---|---|
| src/bin/psql/describe.c | 24 | 1 |
| src/bin/psql/settings.h | 1 | 0 |
| src/bin/psql/startup.c | 8 | 0 |
| src/test/regress/pg_regress_main.c | 2 | 1 |
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 0a181b01d9..f76c734a28 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -1484,6 +1484,8 @@ describeOneTableDetails(const char *schemaname,
char *reloftype;
char relpersistence;
char relreplident;
+ char *relam;
+ bool relam_is_default;
} tableinfo;
bool show_column_details = false;
@@ -1503,9 +1505,11 @@ describeOneTableDetails(const char *schemaname,
"c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
"false AS relhasoids, %s, c.reltablespace, "
"CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
- "c.relpersistence, c.relreplident\n"
+ "c.relpersistence, c.relreplident, am.amname,"
+ "am.amname = current_setting('default_table_access_method') \n"
"FROM pg_catalog.pg_class c\n "
"LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
+ "LEFT JOIN pg_catalog.pg_am am ON (c.relam = am.oid)\n"
"WHERE c.oid = '%s';",
(verbose ?
"pg_catalog.array_to_string(c.reloptions || "
@@ -1656,6 +1660,17 @@ describeOneTableDetails(const char *schemaname,
*(PQgetvalue(res, 0, 11)) : 0;
tableinfo.relreplident = (pset.sversion >= 90400) ?
*(PQgetvalue(res, 0, 12)) : 'd';
+ if (pset.sversion >= 120000)
+ {
+ tableinfo.relam = PQgetisnull(res, 0, 13) ?
+ (char *) NULL : pg_strdup(PQgetvalue(res, 0, 13));
+ tableinfo.relam_is_default = strcmp(PQgetvalue(res, 0, 14), "t") == 0;
+ }
+ else
+ {
+ tableinfo.relam = NULL;
+ tableinfo.relam_is_default = false;
+ }
PQclear(res);
res = NULL;
@@ -3141,6 +3156,14 @@ describeOneTableDetails(const char *schemaname,
/* Tablespace info */
add_tablespace_footer(&cont, tableinfo.relkind, tableinfo.tablespace,
true);
+
+ /* Access method info */
+ if (verbose && tableinfo.relam != NULL &&
+ !(pset.hide_tableam && tableinfo.relam_is_default))
+ {
+ printfPQExpBuffer(&buf, _("Access method: %s"), tableinfo.relam);
+ printTableAddFooter(&cont, buf.data);
+ }
}
/* reloptions, if verbose */
diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h
index 176c85afd0..058233b348 100644
--- a/src/bin/psql/settings.h
+++ b/src/bin/psql/settings.h
@@ -127,6 +127,7 @@ typedef struct _psqlSettings
bool quiet;
bool singleline;
bool singlestep;
+ bool hide_tableam;
int fetch_count;
int histsize;
int ignoreeof;
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index e7536a8a06..b757febcc5 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -1128,6 +1128,11 @@ show_context_hook(const char *newval)
return true;
}
+static bool
+hide_tableam_hook(const char *newval)
+{
+ return ParseVariableBool(newval, "HIDE_TABLEAM", &pset.hide_tableam);
+}
static void
EstablishVariableSpace(void)
@@ -1191,4 +1196,7 @@ EstablishVariableSpace(void)
SetVariableHooks(pset.vars, "SHOW_CONTEXT",
show_context_substitute_hook,
show_context_hook);
+ SetVariableHooks(pset.vars, "HIDE_TABLEAM",
+ bool_substitute_hook,
+ hide_tableam_hook);
}
diff --git a/src/test/regress/pg_regress_main.c b/src/test/regress/pg_regress_main.c
index bd613e4fda..1b4bca704b 100644
--- a/src/test/regress/pg_regress_main.c
+++ b/src/test/regress/pg_regress_main.c
@@ -74,10 +74,11 @@ psql_start_test(const char *testname,
}
offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset,
- "\"%s%spsql\" -X -a -q -d \"%s\" < \"%s\" > \"%s\" 2>&1",
+ "\"%s%spsql\" -X -a -q -d \"%s\" -v %s < \"%s\" > \"%s\" 2>&1",
bindir ? bindir : "",
bindir ? "/" : "",
dblist->str,
+ "HIDE_TABLEAM=\"on\"",
infile,
outfile);
if (offset >= sizeof(psql_cmd))