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/expected/psql.out b/src/test/regress/expected/psql.out index 775b127121..4c9a55a08a 100644 --- a/src/test/regress/expected/psql.out +++ b/src/test/regress/expected/psql.out @@ -2773,6 +2773,44 @@ Argument data types | numeric Type | func \pset tuples_only false +-- check conditional tableam display +-- Create a heap2 table am handler with heapam handler +CREATE ACCESS METHOD heap2 TYPE TABLE HANDLER heap_tableam_handler; +CREATE TABLE tbl_heap2(f1 int, f2 char(100)) using heap2; +CREATE TABLE tbl_heap(f1 int, f2 char(100)) using heap; +\d+ tbl_heap2 + Table "public.tbl_heap2" + Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+----------------+-----------+----------+---------+----------+--------------+------------- + f1 | integer | | | | plain | | + f2 | character(100) | | | | extended | | +Access method: heap2 + +\d+ tbl_heap + Table "public.tbl_heap" + Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+----------------+-----------+----------+---------+----------+--------------+------------- + f1 | integer | | | | plain | | + f2 | character(100) | | | | extended | | + +\set HIDE_TABLEAM off +\d+ tbl_heap2 + Table "public.tbl_heap2" + Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+----------------+-----------+----------+---------+----------+--------------+------------- + f1 | integer | | | | plain | | + f2 | character(100) | | | | extended | | +Access method: heap2 + +\d+ tbl_heap + Table "public.tbl_heap" + Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+----------------+-----------+----------+---------+----------+--------------+------------- + f1 | integer | | | | plain | | + f2 | character(100) | | | | extended | | +Access method: heap + +\set HIDE_TABLEAM on -- test numericlocale (as best we can without control of psql's locale) \pset format aligned \pset expanded off 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)) diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql index 1bb2a6e16d..09ba7b6c14 100644 --- a/src/test/regress/sql/psql.sql +++ b/src/test/regress/sql/psql.sql @@ -448,6 +448,19 @@ select 1 where false; \df exp \pset tuples_only false +-- check conditional tableam display + +-- Create a heap2 table am handler with heapam handler +CREATE ACCESS METHOD heap2 TYPE TABLE HANDLER heap_tableam_handler; +CREATE TABLE tbl_heap2(f1 int, f2 char(100)) using heap2; +CREATE TABLE tbl_heap(f1 int, f2 char(100)) using heap; +\d+ tbl_heap2 +\d+ tbl_heap +\set HIDE_TABLEAM off +\d+ tbl_heap2 +\d+ tbl_heap +\set HIDE_TABLEAM on + -- test numericlocale (as best we can without control of psql's locale) \pset format aligned