On Mon, 30 Dec 2024 at 15:48, Greg Sabino Mullane <htamf...@gmail.com> wrote:
>
> I like this, very useful. It's a shame about the conflict with \dx (lesson 
> for the future: think extra carefully about option namings!). I am impressed 
> that \dx   \d   \d+   \d+x  and even \dxx all work as one might intuit with 
> this patch.
>

Thanks for looking.

Attached is a more complete patch, now with
 - trivial bug-fix for previous \d code, per cfbot
 - expanded mode support for \l and \z
 - updated psql help
 - a few representative regression test cases

The majority of the patch is doc updates, which are somewhat tedious.
Initially, I resisted documenting the 'x' option in the description of
every command affected, but given the length of the list of commands
in the HTML page, it's a long way from any given command to the top or
bottom where 'x' is described in more detail. So in the end, I decided
to just add a sentence to each command's description, keeping it as
short as possible.

Regards,
Dean
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
new file mode 100644
index 72f3347..c48bcfb
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -865,6 +865,13 @@ testdb=&gt;
     </para>
 
     <para>
+    Many of the meta-commands also allow <literal>x</literal> to be appended
+    as an option. This will cause the results to be displayed in expanded
+    mode, as if <literal>expanded=on</literal> were included in the list of
+    <literal>\pset</literal> options. See also <literal>\x</literal>.
+    </para>
+
+    <para>
     The following meta-commands are defined:
 
     <variablelist>
@@ -1272,7 +1279,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-d">
-        <term><literal>\d[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\d[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
 
         <listitem>
         <para>
@@ -1321,12 +1328,24 @@ SELECT $1 \parse stmt1
         foreign tables.
         This is purely a convenience measure.
         </para>
+        <para>
+        As with many other commands, if <literal>x</literal> is appended to
+        the command name, the results are displayed in expanded mode, but note
+        that this only applies when <command>\d</command> is used without a
+        <replaceable class="parameter">pattern</replaceable> argument, and
+        the <literal>x</literal> modifier cannot appear immediately after the
+        <command>\d</command> (because <command>\dx</command> is a different
+        command); the <literal>x</literal> modifier may only appear after an
+        <literal>S</literal> or <literal>+</literal> modifier. For example,
+        <command>\d+x</command> is equivalent to <command>\dtvmsE+x</command>
+        and will show a list of all relations in expanded mode.
+        </para>
         </note>
         </listitem>
       </varlistentry>
 
       <varlistentry id="app-psql-meta-command-da-lc">
-        <term><literal>\da[S] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\da[Sx] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
 
         <listitem>
         <para>
@@ -1337,19 +1356,23 @@ SELECT $1 \parse stmt1
         By default, only user-created objects are shown;  supply a
         pattern or the <literal>S</literal> modifier to include system
         objects.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         </para>
         </listitem>
       </varlistentry>
 
       <varlistentry id="app-psql-meta-command-da-uc">
-        <term><literal>\dA[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dA[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
 
         <listitem>
         <para>
         Lists access methods. If <replaceable
         class="parameter">pattern</replaceable> is specified, only access
-        methods whose names match the pattern are shown. If
-        <literal>+</literal> is appended to the command name, each access
+        methods whose names match the pattern are shown.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
+        If <literal>+</literal> is appended to the command name, each access
         method is listed with its associated handler function and description.
         </para>
         </listitem>
@@ -1357,7 +1380,7 @@ SELECT $1 \parse stmt1
 
       <varlistentry id="app-psql-meta-command-dac">
         <term>
-          <literal>\dAc[+]
+          <literal>\dAc[x+]
             [<link linkend="app-psql-patterns"><replaceable class="parameter">access-method-pattern</replaceable></link>
               [<link linkend="app-psql-patterns"><replaceable class="parameter">input-type-pattern</replaceable></link>]]
           </literal>
@@ -1372,6 +1395,8 @@ SELECT $1 \parse stmt1
         If <replaceable class="parameter">input-type-pattern</replaceable>
         is specified, only operator classes associated with input types whose
         names match that pattern are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, each operator
         class is listed with its associated operator family and owner.
         </para>
@@ -1380,7 +1405,7 @@ SELECT $1 \parse stmt1
 
       <varlistentry id="app-psql-meta-command-daf">
         <term>
-          <literal>\dAf[+]
+          <literal>\dAf[x+]
             [<link linkend="app-psql-patterns"><replaceable class="parameter">access-method-pattern</replaceable></link>
               [<link linkend="app-psql-patterns"><replaceable class="parameter">input-type-pattern</replaceable></link>]]
           </literal>
@@ -1395,6 +1420,8 @@ SELECT $1 \parse stmt1
         If <replaceable class="parameter">input-type-pattern</replaceable>
         is specified, only operator families associated with input types whose
         names match that pattern are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, each operator
         family is listed with its owner.
         </para>
@@ -1403,7 +1430,7 @@ SELECT $1 \parse stmt1
 
       <varlistentry id="app-psql-meta-command-dao">
         <term>
-          <literal>\dAo[+]
+          <literal>\dAo[x+]
             [<link linkend="app-psql-patterns"><replaceable class="parameter">access-method-pattern</replaceable></link>
               [<link linkend="app-psql-patterns"><replaceable class="parameter">operator-family-pattern</replaceable></link>]]
           </literal>
@@ -1419,6 +1446,8 @@ SELECT $1 \parse stmt1
         If <replaceable class="parameter">operator-family-pattern</replaceable>
         is specified, only members of operator families whose names match that
         pattern are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, each operator
         is listed with its sort operator family (if it is an ordering operator).
         </para>
@@ -1427,7 +1456,7 @@ SELECT $1 \parse stmt1
 
       <varlistentry id="app-psql-meta-command-dap">
         <term>
-          <literal>\dAp[+]
+          <literal>\dAp[x+]
             [<link linkend="app-psql-patterns"><replaceable class="parameter">access-method-pattern</replaceable></link>
               [<link linkend="app-psql-patterns"><replaceable class="parameter">operator-family-pattern</replaceable></link>]]
           </literal>
@@ -1442,6 +1471,8 @@ SELECT $1 \parse stmt1
         If <replaceable class="parameter">operator-family-pattern</replaceable>
         is specified, only functions of operator families whose names match
         that pattern are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, functions are
         displayed verbosely, with their actual parameter lists.
         </para>
@@ -1449,13 +1480,15 @@ SELECT $1 \parse stmt1
       </varlistentry>
 
       <varlistentry id="app-psql-meta-command-db">
-        <term><literal>\db[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\db[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
 
         <listitem>
         <para>
         Lists tablespaces. If <replaceable
         class="parameter">pattern</replaceable>
         is specified, only tablespaces whose names match the pattern are shown.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, each tablespace
         is listed with its associated options, on-disk size, permissions and
         description.
@@ -1465,7 +1498,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-dc-lc">
-        <term><literal>\dc[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dc[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists conversions between character-set encodings.
@@ -1475,6 +1508,8 @@ SELECT $1 \parse stmt1
         By default, only user-created objects are shown;  supply a
         pattern or the <literal>S</literal> modifier to include system
         objects.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, each object
         is listed with its associated description.
         </para>
@@ -1483,7 +1518,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-dconfig">
-        <term><literal>\dconfig[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dconfig[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists server configuration parameters and their values.
@@ -1492,6 +1527,8 @@ SELECT $1 \parse stmt1
         a <replaceable class="parameter">pattern</replaceable>, only
         parameters that are set to non-default values are listed.
         (Use <literal>\dconfig *</literal> to see all parameters.)
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, each
         parameter is listed with its data type, context in which the
         parameter can be set, and access privileges (if non-default access
@@ -1502,13 +1539,15 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-dc-uc">
-        <term><literal>\dC[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dC[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists type casts.
         If <replaceable class="parameter">pattern</replaceable>
         is specified, only casts whose source or target types match the
         pattern are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, each object
         is listed with its associated description.
         </para>
@@ -1517,7 +1556,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-dd-lc">
-        <term><literal>\dd[S] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dd[Sx] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Shows the descriptions of objects of type <literal>constraint</literal>,
@@ -1534,6 +1573,8 @@ SELECT $1 \parse stmt1
         By default, only user-created objects are shown;  supply a
         pattern or the <literal>S</literal> modifier to include system
         objects.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         </para>
 
         <para>
@@ -1546,7 +1587,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-dd-uc">
-        <term><literal>\dD[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dD[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists domains. If <replaceable
@@ -1555,6 +1596,8 @@ SELECT $1 \parse stmt1
         By default, only user-created objects are shown;  supply a
         pattern or the <literal>S</literal> modifier to include system
         objects.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, each object
         is listed with its associated permissions and description.
         </para>
@@ -1563,7 +1606,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-ddp">
-        <term><literal>\ddp [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\ddp[x] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists default access privilege settings.  An entry is shown for
@@ -1572,6 +1615,8 @@ SELECT $1 \parse stmt1
         If <replaceable class="parameter">pattern</replaceable> is
         specified, only entries whose role name or schema name matches
         the pattern are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         </para>
 
         <para>
@@ -1585,12 +1630,12 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-de">
-        <term><literal>\dE[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
-        <term><literal>\di[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
-        <term><literal>\dm[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
-        <term><literal>\ds[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
-        <term><literal>\dt[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
-        <term><literal>\dv[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dE[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\di[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dm[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\ds[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dt[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dv[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
 
         <listitem>
         <para>
@@ -1603,7 +1648,10 @@ SELECT $1 \parse stmt1
         You can specify any or all of
         these letters, in any order, to obtain a listing of objects
         of these types.  For example, <literal>\dti</literal> lists
-        tables and indexes.  If <literal>+</literal> is
+        tables and indexes.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
+        If <literal>+</literal> is
         appended to the command name, each object is listed with its
         persistence status (permanent, temporary, or unlogged),
         physical size on disk, and associated description if any.
@@ -1618,14 +1666,17 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-des">
-        <term><literal>\des[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\des[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists foreign servers (mnemonic: <quote>external
         servers</quote>).
         If <replaceable class="parameter">pattern</replaceable> is
         specified, only those servers whose name matches the pattern
-        are listed.  If the form <literal>\des+</literal> is used, a
+        are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
+        If <literal>+</literal> is appended to the command name, a
         full description of each server is shown, including the
         server's access privileges, type, version, options, and description.
         </para>
@@ -1634,14 +1685,17 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-det">
-        <term><literal>\det[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\det[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists foreign tables (mnemonic: <quote>external tables</quote>).
         If <replaceable class="parameter">pattern</replaceable> is
         specified, only entries whose table name or schema name matches
-        the pattern are listed.  If the form <literal>\det+</literal>
-        is used, generic options and the foreign table description
+        the pattern are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
+        If <literal>+</literal> is appended to the command name,
+        generic options and the foreign table description
         are also displayed.
         </para>
         </listitem>
@@ -1649,15 +1703,18 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-deu">
-        <term><literal>\deu[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\deu[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists user mappings (mnemonic: <quote>external
         users</quote>).
         If <replaceable class="parameter">pattern</replaceable> is
         specified, only those mappings whose user names match the
-        pattern are listed.  If the form <literal>\deu+</literal> is
-        used, additional information about each mapping is shown.
+        pattern are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
+        If <literal>+</literal> is appended to the command name,
+        additional information about each mapping is shown.
         </para>
 
         <caution>
@@ -1672,15 +1729,18 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-dew">
-        <term><literal>\dew[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dew[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists foreign-data wrappers (mnemonic: <quote>external
         wrappers</quote>).
         If <replaceable class="parameter">pattern</replaceable> is
         specified, only those foreign-data wrappers whose name matches
-        the pattern are listed.  If the form <literal>\dew+</literal>
-        is used, the access privileges, options, and description of the
+        the pattern are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
+        If <literal>+</literal> is appended to the command name,
+        the access privileges, options, and description of the
         foreign-data wrapper are also shown.
         </para>
         </listitem>
@@ -1688,7 +1748,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-df-lc">
-        <term><literal>\df[anptwS+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> [ <replaceable class="parameter">arg_pattern</replaceable> ... ] ]</literal></term>
+        <term><literal>\df[anptwSx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> [ <replaceable class="parameter">arg_pattern</replaceable> ... ] ]</literal></term>
 
         <listitem>
         <para>
@@ -1709,7 +1769,9 @@ SELECT $1 \parse stmt1
         By default, only user-created
         objects are shown; supply a pattern or the <literal>S</literal>
         modifier to include system objects.
-        If the form <literal>\df+</literal> is used, additional information
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
+        If <literal>+</literal> is appended to the command name, additional information
         about each function is shown, including volatility,
         parallel safety, owner, security classification, access privileges,
         language, internal name (for C and internal functions only),
@@ -1722,13 +1784,15 @@ SELECT $1 \parse stmt1
       </varlistentry>
 
       <varlistentry id="app-psql-meta-command-df-uc">
-        <term><literal>\dF[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dF[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
          Lists text search configurations.
          If <replaceable class="parameter">pattern</replaceable> is specified,
          only configurations whose names match the pattern are shown.
-         If the form <literal>\dF+</literal> is used, a full description of
+         If <literal>x</literal> is appended to the command name, the results
+         are displayed in expanded mode.
+         If <literal>+</literal> is appended to the command name, a full description of
          each configuration is shown, including the underlying text search
          parser and the dictionary list for each parser token type.
         </para>
@@ -1736,13 +1800,15 @@ SELECT $1 \parse stmt1
       </varlistentry>
 
       <varlistentry id="app-psql-meta-command-dfd">
-        <term><literal>\dFd[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dFd[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
          Lists text search dictionaries.
          If <replaceable class="parameter">pattern</replaceable> is specified,
          only dictionaries whose names match the pattern are shown.
-         If the form <literal>\dFd+</literal> is used, additional information
+         If <literal>x</literal> is appended to the command name, the results
+         are displayed in expanded mode.
+         If <literal>+</literal> is appended to the command name, additional information
          is shown about each selected dictionary, including the underlying
          text search template and the option values.
         </para>
@@ -1750,13 +1816,15 @@ SELECT $1 \parse stmt1
       </varlistentry>
 
       <varlistentry id="app-psql-meta-command-dfp">
-        <term><literal>\dFp[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dFp[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
          Lists text search parsers.
          If <replaceable class="parameter">pattern</replaceable> is specified,
          only parsers whose names match the pattern are shown.
-         If the form <literal>\dFp+</literal> is used, a full description of
+         If <literal>x</literal> is appended to the command name, the results
+         are displayed in expanded mode.
+         If <literal>+</literal> is appended to the command name, a full description of
          each parser is shown, including the underlying functions and the
          list of recognized token types.
         </para>
@@ -1764,13 +1832,15 @@ SELECT $1 \parse stmt1
       </varlistentry>
 
       <varlistentry id="app-psql-meta-command-dft">
-        <term><literal>\dFt[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dFt[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
          Lists text search templates.
          If <replaceable class="parameter">pattern</replaceable> is specified,
          only templates whose names match the pattern are shown.
-         If the form <literal>\dFt+</literal> is used, additional information
+         If <literal>x</literal> is appended to the command name, the results
+         are displayed in expanded mode.
+         If <literal>+</literal> is appended to the command name, additional information
          is shown about each template, including the underlying function names.
         </para>
         </listitem>
@@ -1778,7 +1848,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-dg">
-        <term><literal>\dg[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dg[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists database roles.
@@ -1789,7 +1859,9 @@ SELECT $1 \parse stmt1
         <literal>S</literal> modifier to include system roles.
         If <replaceable class="parameter">pattern</replaceable> is specified,
         only those roles whose names match the pattern are listed.
-        If the form <literal>\dg+</literal> is used, additional information
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
+        If <literal>+</literal> is appended to the command name, additional information
         is shown about each role; currently this adds the comment for each
         role.
         </para>
@@ -1798,11 +1870,13 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-dl-lc">
-        <term><literal>\dl[+]</literal></term>
+        <term><literal>\dl[x+]</literal></term>
         <listitem>
         <para>
         This is an alias for <command>\lo_list</command>, which shows a
         list of large objects.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name,
         each large object is listed with its associated permissions,
         if any.
@@ -1811,7 +1885,7 @@ SELECT $1 \parse stmt1
       </varlistentry>
 
       <varlistentry id="app-psql-meta-command-dl-uc">
-        <term><literal>\dL[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dL[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists procedural languages. If <replaceable
@@ -1819,7 +1893,10 @@ SELECT $1 \parse stmt1
         is specified, only languages whose names match the pattern are listed.
         By default, only user-created languages
         are shown; supply the <literal>S</literal> modifier to include system
-        objects. If <literal>+</literal> is appended to the command name, each
+        objects.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
+        If <literal>+</literal> is appended to the command name, each
         language is listed with its call handler, validator, access privileges,
         and whether it is a system object.
         </para>
@@ -1828,7 +1905,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-dn">
-        <term><literal>\dn[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dn[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
 
         <listitem>
         <para>
@@ -1837,6 +1914,8 @@ SELECT $1 \parse stmt1
         is specified, only schemas whose names match the pattern are listed.
         By default, only user-created objects are shown; supply a
         pattern or the <literal>S</literal> modifier to include system objects.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, each object
         is listed with its associated permissions and description, if any.
         </para>
@@ -1845,7 +1924,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-do-lc">
-        <term><literal>\do[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> [ <replaceable class="parameter">arg_pattern</replaceable> [ <replaceable class="parameter">arg_pattern</replaceable> ] ] ]</literal></term>
+        <term><literal>\do[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> [ <replaceable class="parameter">arg_pattern</replaceable> [ <replaceable class="parameter">arg_pattern</replaceable> ] ] ]</literal></term>
         <listitem>
         <para>
         Lists operators with their operand and result types.
@@ -1861,6 +1940,8 @@ SELECT $1 \parse stmt1
         By default, only user-created objects are shown; supply a
         pattern or the <literal>S</literal> modifier to include system
         objects.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name,
         additional information about each operator is shown, currently just
         the name of the underlying function.
@@ -1870,7 +1951,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-do-uc">
-        <term><literal>\dO[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dO[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists collations.
@@ -1878,7 +1959,10 @@ SELECT $1 \parse stmt1
         specified, only collations whose names match the pattern are
         listed.  By default, only user-created objects are shown;
         supply a pattern or the <literal>S</literal> modifier to
-        include system objects.  If <literal>+</literal> is appended
+        include system objects.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
+        If <literal>+</literal> is appended
         to the command name, each collation is listed with its associated
         description, if any.
         Note that only collations usable with the current database's encoding
@@ -1890,7 +1974,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-dp-lc">
-        <term><literal>\dp[S] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dp[Sx] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists tables, views and sequences with their
@@ -1900,6 +1984,8 @@ SELECT $1 \parse stmt1
         pattern are listed.  By default only user-created objects are shown;
         supply a pattern or the <literal>S</literal> modifier to include
         system objects.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         </para>
 
         <para>
@@ -1914,7 +2000,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-dp-uc">
-        <term><literal>\dP[itn+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dP[itnx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists partitioned relations.
@@ -1934,6 +2020,8 @@ SELECT $1 \parse stmt1
         </para>
 
         <para>
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, the sum of the
         sizes of each relation's partitions is also displayed, along with the
         relation's description.
@@ -1947,7 +2035,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-drds">
-        <term><literal>\drds [ <link linkend="app-psql-patterns"><replaceable class="parameter">role-pattern</replaceable></link> [ <link linkend="app-psql-patterns"><replaceable class="parameter">database-pattern</replaceable></link> ] ]</literal></term>
+        <term><literal>\drds[x] [ <link linkend="app-psql-patterns"><replaceable class="parameter">role-pattern</replaceable></link> [ <link linkend="app-psql-patterns"><replaceable class="parameter">database-pattern</replaceable></link> ] ]</literal></term>
         <listitem>
         <para>
         Lists defined configuration settings.  These settings can be
@@ -1957,6 +2045,8 @@ SELECT $1 \parse stmt1
         specific roles and databases to list, respectively.  If omitted, or if
         <literal>*</literal> is specified, all settings are listed, including those
         not role-specific or database-specific, respectively.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         </para>
 
         <para>
@@ -1970,7 +2060,7 @@ SELECT $1 \parse stmt1
 
 
       <varlistentry id="app-psql-meta-command-drg">
-        <term><literal>\drg[S] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\drg[Sx] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists information about each granted role membership, including
@@ -1984,19 +2074,23 @@ SELECT $1 \parse stmt1
         <literal>S</literal> modifier to include system roles.
         If <replaceable class="parameter">pattern</replaceable> is specified,
         only grants to those roles whose names match the pattern are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         </para>
         </listitem>
       </varlistentry>
 
 
       <varlistentry id="app-psql-meta-command-drp">
-        <term><literal>\dRp[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dRp[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists replication publications.
         If <replaceable class="parameter">pattern</replaceable> is
         specified, only those publications whose names match the pattern are
         listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, the tables and
         schemas associated with each publication are shown as well.
         </para>
@@ -2004,13 +2098,15 @@ SELECT $1 \parse stmt1
       </varlistentry>
 
       <varlistentry id="app-psql-meta-command-drs">
-        <term><literal>\dRs[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dRs[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists replication subscriptions.
         If <replaceable class="parameter">pattern</replaceable> is
         specified, only those subscriptions whose names match the pattern are
         listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, additional
         properties of the subscriptions are shown.
         </para>
@@ -2018,12 +2114,14 @@ SELECT $1 \parse stmt1
       </varlistentry>
 
       <varlistentry id="app-psql-meta-command-dt">
-        <term><literal>\dT[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dT[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists data types.
         If <replaceable class="parameter">pattern</replaceable> is
         specified, only types whose names match the pattern are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, each type is
         listed with its internal name and size, its allowed values
         if it is an <type>enum</type> type, and its associated permissions.
@@ -2035,7 +2133,7 @@ SELECT $1 \parse stmt1
       </varlistentry>
 
       <varlistentry id="app-psql-meta-command-du">
-        <term><literal>\du[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\du[Sx+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists database roles.
@@ -2046,7 +2144,9 @@ SELECT $1 \parse stmt1
         <literal>S</literal> modifier to include system roles.
         If <replaceable class="parameter">pattern</replaceable> is specified,
         only those roles whose names match the pattern are listed.
-        If the form <literal>\du+</literal> is used, additional information
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
+        If <literal>+</literal> is appended to the command name, additional information
         is shown about each role; currently this adds the comment for each
         role.
         </para>
@@ -2054,27 +2154,31 @@ SELECT $1 \parse stmt1
       </varlistentry>
 
       <varlistentry id="app-psql-meta-command-dx-lc">
-        <term><literal>\dx[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dx[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists installed extensions.
         If <replaceable class="parameter">pattern</replaceable>
         is specified, only those extensions whose names match the pattern
         are listed.
-        If the form <literal>\dx+</literal> is used, all the objects belonging
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
+        If <literal>+</literal> is appended to the command name, all the objects belonging
         to each matching extension are listed.
         </para>
         </listitem>
       </varlistentry>
 
       <varlistentry id="app-psql-meta-command-dx-uc">
-        <term><literal>\dX [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dX[x] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists extended statistics.
         If <replaceable class="parameter">pattern</replaceable>
         is specified, only those extended statistics whose names match the
         pattern are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         </para>
 
         <para>
@@ -2090,13 +2194,15 @@ SELECT $1 \parse stmt1
       </varlistentry>
 
       <varlistentry id="app-psql-meta-command-dy">
-        <term><literal>\dy[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dy[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists event triggers.
         If <replaceable class="parameter">pattern</replaceable>
         is specified, only those event triggers whose names match the pattern
         are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, each object
         is listed with its associated description.
         </para>
@@ -2684,13 +2790,15 @@ SELECT
 
 
       <varlistentry id="app-psql-meta-command-list">
-        <term><literal>\l[+]</literal> or <literal>\list[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\l[x+]</literal> or <literal>\list[x+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         List the databases in the server and show their names, owners,
         character set encodings, and access privileges.
         If <replaceable class="parameter">pattern</replaceable> is specified,
         only databases whose names match the pattern are listed.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         If <literal>+</literal> is appended to the command name, database
         sizes, default tablespaces, and descriptions are also displayed.
         (Size information is only available for databases that the current
@@ -3693,7 +3801,7 @@ testdb=&gt; <userinput>\setenv LESS -imx
 
 
       <varlistentry id="app-psql-meta-command-z">
-        <term><literal>\z[S] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\z[Sx] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
         Lists tables, views and sequences with their
@@ -3703,6 +3811,8 @@ testdb=&gt; <userinput>\setenv LESS -imx
         pattern are listed.  By default only user-created objects are shown;
         supply a pattern or the <literal>S</literal> modifier to include
         system objects.
+        If <literal>x</literal> is appended to the command name, the results
+        are displayed in expanded mode.
         </para>
 
         <para>
@@ -5386,6 +5496,30 @@ testdb=&gt; <userinput>\df int*pl * bigi
 </programlisting>
   </para>
 
+  <para>
+   Here, the <literal>+</literal> option is used to display additional
+   information about one of these functions, and <literal>x</literal> is used
+   to display the results in expanded mode:
+<programlisting>
+testdb=&gt; <userinput>\df+x int4*pl * bigint</userinput>
+List of functions
+-[ RECORD 1 ]-------+-----------------------------
+Schema              | pg_catalog
+Name                | int48pl
+Result data type    | bigint
+Argument data types | integer, bigint
+Type                | func
+Volatility          | immutable
+Parallel            | safe
+Owner               | pgdevel
+Security            | invoker
+Access privileges   |
+Language            | internal
+Internal name       | int48pl
+Description         | implementation of + operator
+</programlisting>
+  </para>
+
   <para>
   When suitable, query results can be shown in a crosstab representation
   with the <command>\crosstabview</command> command:
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
new file mode 100644
index 5dd4c2d..8eda1fd
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -377,7 +377,10 @@ exec_command(const char *cmd,
 	else if (strcmp(cmd, "if") == 0)
 		status = exec_command_if(scan_state, cstack, query_buf);
 	else if (strcmp(cmd, "l") == 0 || strcmp(cmd, "list") == 0 ||
-			 strcmp(cmd, "l+") == 0 || strcmp(cmd, "list+") == 0)
+			 strcmp(cmd, "lx") == 0 || strcmp(cmd, "listx") == 0 ||
+			 strcmp(cmd, "l+") == 0 || strcmp(cmd, "list+") == 0 ||
+			 strcmp(cmd, "lx+") == 0 || strcmp(cmd, "listx+") == 0 ||
+			 strcmp(cmd, "l+x") == 0 || strcmp(cmd, "list+x") == 0)
 		status = exec_command_list(scan_state, active_branch, cmd);
 	else if (strncmp(cmd, "lo_", 3) == 0)
 		status = exec_command_lo(scan_state, active_branch, cmd);
@@ -424,7 +427,9 @@ exec_command(const char *cmd,
 									query_buf, previous_buf);
 	else if (strcmp(cmd, "x") == 0)
 		status = exec_command_x(scan_state, active_branch);
-	else if (strcmp(cmd, "z") == 0 || strcmp(cmd, "zS") == 0)
+	else if (strcmp(cmd, "z") == 0 ||
+			 strcmp(cmd, "zS") == 0 || strcmp(cmd, "zx") == 0 ||
+			 strcmp(cmd, "zSx") == 0 || strcmp(cmd, "zxS") == 0)
 		status = exec_command_z(scan_state, active_branch, cmd);
 	else if (strcmp(cmd, "!") == 0)
 		status = exec_command_shell_escape(scan_state, active_branch);
@@ -850,6 +855,7 @@ exec_command_d(PsqlScanState scan_state,
 		char	   *pattern;
 		bool		show_verbose,
 					show_system;
+		unsigned short int save_expanded;
 
 		/* We don't do SQLID reduction on the pattern yet */
 		pattern = psql_scan_slash_option(scan_state,
@@ -858,6 +864,16 @@ exec_command_d(PsqlScanState scan_state,
 		show_verbose = strchr(cmd, '+') ? true : false;
 		show_system = strchr(cmd, 'S') ? true : false;
 
+		/*
+		 * The 'x' option turns expanded mode on for this command only. This
+		 * is allowed in all \d* commands, except \d by itself, since \dx is a
+		 * separate command. So the 'x' option cannot appear immediately after
+		 * \d, but it can appear after \d followed by other options.
+		 */
+		save_expanded = pset.popt.topt.expanded;
+		if (cmd[1] != '\0' && strchr(&cmd[2], 'x'))
+			pset.popt.topt.expanded = 1;
+
 		switch (cmd[1])
 		{
 			case '\0':
@@ -873,13 +889,14 @@ exec_command_d(PsqlScanState scan_state,
 				{
 					char	   *pattern2 = NULL;
 
-					if (pattern && cmd[2] != '\0' && cmd[2] != '+')
+					if (pattern && cmd[2] != '\0' && cmd[2] != '+' && cmd[2] != 'x')
 						pattern2 = psql_scan_slash_option(scan_state, OT_NORMAL, NULL, true);
 
 					switch (cmd[2])
 					{
 						case '\0':
 						case '+':
+						case 'x':
 							success = describeAccessMethods(pattern, show_verbose);
 							break;
 						case 'c':
@@ -941,6 +958,7 @@ exec_command_d(PsqlScanState scan_state,
 					case 'p':
 					case 't':
 					case 'w':
+					case 'x':
 						success = exec_command_dfo(scan_state, cmd, pattern,
 												   show_verbose, show_system);
 						break;
@@ -981,6 +999,7 @@ exec_command_d(PsqlScanState scan_state,
 						case 't':
 						case 'i':
 						case 'n':
+						case 'x':
 							success = listPartitionedTables(&cmd[2], pattern, show_verbose);
 							break;
 						default:
@@ -1041,6 +1060,7 @@ exec_command_d(PsqlScanState scan_state,
 				{
 					case '\0':
 					case '+':
+					case 'x':
 						success = listTSConfigs(pattern, show_verbose);
 						break;
 					case 'p':
@@ -1093,6 +1113,9 @@ exec_command_d(PsqlScanState scan_state,
 				status = PSQL_CMD_UNKNOWN;
 		}
 
+		/* Restore original expanded mode */
+		pset.popt.topt.expanded = save_expanded;
+
 		free(pattern);
 	}
 	else
@@ -2044,14 +2067,23 @@ exec_command_list(PsqlScanState scan_sta
 	{
 		char	   *pattern;
 		bool		show_verbose;
+		unsigned short int save_expanded;
 
 		pattern = psql_scan_slash_option(scan_state,
 										 OT_NORMAL, NULL, true);
 
 		show_verbose = strchr(cmd, '+') ? true : false;
 
+		/* if 'x' option specified, force expanded mode */
+		save_expanded = pset.popt.topt.expanded;
+		if (strchr(cmd, 'x'))
+			pset.popt.topt.expanded = 1;
+
 		success = listAllDbs(pattern, show_verbose);
 
+		/* restore original expanded mode */
+		pset.popt.topt.expanded = save_expanded;
+
 		free(pattern);
 	}
 	else
@@ -3061,14 +3093,23 @@ exec_command_z(PsqlScanState scan_state,
 	{
 		char	   *pattern;
 		bool		show_system;
+		unsigned short int save_expanded;
 
 		pattern = psql_scan_slash_option(scan_state,
 										 OT_NORMAL, NULL, true);
 
 		show_system = strchr(cmd, 'S') ? true : false;
 
+		/* if 'x' option specified, force expanded mode */
+		save_expanded = pset.popt.topt.expanded;
+		if (strchr(cmd, 'x'))
+			pset.popt.topt.expanded = 1;
+
 		success = permissionsList(pattern, show_system);
 
+		/* restore original expanded mode */
+		pset.popt.topt.expanded = save_expanded;
+
 		free(pattern);
 	}
 	else
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
new file mode 100644
index d5543fd..9c2d522
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -309,9 +309,9 @@ describeFunctions(const char *functypes,
 	/* No "Parallel" column before 9.6 */
 	static const bool translate_columns_pre_96[] = {false, false, false, false, true, true, false, true, false, false, false, false};
 
-	if (strlen(functypes) != strspn(functypes, "anptwS+"))
+	if (strlen(functypes) != strspn(functypes, "anptwSx+"))
 	{
-		pg_log_error("\\df only takes [anptwS+] as options");
+		pg_log_error("\\df only takes [anptwSx+] as options");
 		return true;
 	}
 
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
new file mode 100644
index fda8346..837651e
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -219,60 +219,60 @@ slashUsage(unsigned short int pager)
 	HELP0("\n");
 
 	HELP0("Informational\n");
-	HELP0("  (options: S = show system objects, + = additional detail)\n");
-	HELP0("  \\d[S+]                 list tables, views, and sequences\n");
-	HELP0("  \\d[S+]  NAME           describe table, view, sequence, or index\n");
-	HELP0("  \\da[S]  [PATTERN]      list aggregates\n");
-	HELP0("  \\dA[+]  [PATTERN]      list access methods\n");
-	HELP0("  \\dAc[+] [AMPTRN [TYPEPTRN]]  list operator classes\n");
-	HELP0("  \\dAf[+] [AMPTRN [TYPEPTRN]]  list operator families\n");
-	HELP0("  \\dAo[+] [AMPTRN [OPFPTRN]]   list operators of operator families\n");
-	HELP0("  \\dAp[+] [AMPTRN [OPFPTRN]]   list support functions of operator families\n");
-	HELP0("  \\db[+]  [PATTERN]      list tablespaces\n");
-	HELP0("  \\dc[S+] [PATTERN]      list conversions\n");
-	HELP0("  \\dconfig[+] [PATTERN]  list configuration parameters\n");
-	HELP0("  \\dC[+]  [PATTERN]      list casts\n");
-	HELP0("  \\dd[S]  [PATTERN]      show object descriptions not displayed elsewhere\n");
-	HELP0("  \\dD[S+] [PATTERN]      list domains\n");
-	HELP0("  \\ddp    [PATTERN]      list default privileges\n");
-	HELP0("  \\dE[S+] [PATTERN]      list foreign tables\n");
-	HELP0("  \\des[+] [PATTERN]      list foreign servers\n");
-	HELP0("  \\det[+] [PATTERN]      list foreign tables\n");
-	HELP0("  \\deu[+] [PATTERN]      list user mappings\n");
-	HELP0("  \\dew[+] [PATTERN]      list foreign-data wrappers\n");
-	HELP0("  \\df[anptw][S+] [FUNCPTRN [TYPEPTRN ...]]\n"
+	HELP0("  (options: S = show system objects, x = expanded mode, + = additional detail)\n");
+	HELP0("  \\d[Sx+]                list tables, views, and sequences\n");
+	HELP0("  \\d[S+]   NAME          describe table, view, sequence, or index\n");
+	HELP0("  \\da[Sx]  [PATTERN]     list aggregates\n");
+	HELP0("  \\dA[x+]  [PATTERN]     list access methods\n");
+	HELP0("  \\dAc[x+] [AMPTRN [TYPEPTRN]]  list operator classes\n");
+	HELP0("  \\dAf[x+] [AMPTRN [TYPEPTRN]]  list operator families\n");
+	HELP0("  \\dAo[x+] [AMPTRN [OPFPTRN]]   list operators of operator families\n");
+	HELP0("  \\dAp[x+] [AMPTRN [OPFPTRN]]   list support functions of operator families\n");
+	HELP0("  \\db[x+]  [PATTERN]     list tablespaces\n");
+	HELP0("  \\dc[Sx+] [PATTERN]     list conversions\n");
+	HELP0("  \\dconfig[x+] [PATTERN] list configuration parameters\n");
+	HELP0("  \\dC[x+]  [PATTERN]     list casts\n");
+	HELP0("  \\dd[Sx]  [PATTERN]     show object descriptions not displayed elsewhere\n");
+	HELP0("  \\dD[Sx+] [PATTERN]     list domains\n");
+	HELP0("  \\ddp[x]  [PATTERN]     list default privileges\n");
+	HELP0("  \\dE[Sx+] [PATTERN]     list foreign tables\n");
+	HELP0("  \\des[x+] [PATTERN]     list foreign servers\n");
+	HELP0("  \\det[x+] [PATTERN]     list foreign tables\n");
+	HELP0("  \\deu[x+] [PATTERN]     list user mappings\n");
+	HELP0("  \\dew[x+] [PATTERN]     list foreign-data wrappers\n");
+	HELP0("  \\df[anptw][Sx+] [FUNCPTRN [TYPEPTRN ...]]\n"
 		  "                         list [only agg/normal/procedure/trigger/window] functions\n");
-	HELP0("  \\dF[+]  [PATTERN]      list text search configurations\n");
-	HELP0("  \\dFd[+] [PATTERN]      list text search dictionaries\n");
-	HELP0("  \\dFp[+] [PATTERN]      list text search parsers\n");
-	HELP0("  \\dFt[+] [PATTERN]      list text search templates\n");
-	HELP0("  \\dg[S+] [PATTERN]      list roles\n");
-	HELP0("  \\di[S+] [PATTERN]      list indexes\n");
-	HELP0("  \\dl[+]                 list large objects, same as \\lo_list\n");
-	HELP0("  \\dL[S+] [PATTERN]      list procedural languages\n");
-	HELP0("  \\dm[S+] [PATTERN]      list materialized views\n");
-	HELP0("  \\dn[S+] [PATTERN]      list schemas\n");
-	HELP0("  \\do[S+] [OPPTRN [TYPEPTRN [TYPEPTRN]]]\n"
+	HELP0("  \\dF[x+]  [PATTERN]     list text search configurations\n");
+	HELP0("  \\dFd[x+] [PATTERN]     list text search dictionaries\n");
+	HELP0("  \\dFp[x+] [PATTERN]     list text search parsers\n");
+	HELP0("  \\dFt[x+] [PATTERN]     list text search templates\n");
+	HELP0("  \\dg[Sx+] [PATTERN]     list roles\n");
+	HELP0("  \\di[Sx+] [PATTERN]     list indexes\n");
+	HELP0("  \\dl[x+]                list large objects, same as \\lo_list\n");
+	HELP0("  \\dL[Sx+] [PATTERN]     list procedural languages\n");
+	HELP0("  \\dm[Sx+] [PATTERN]     list materialized views\n");
+	HELP0("  \\dn[Sx+] [PATTERN]     list schemas\n");
+	HELP0("  \\do[Sx+] [OPPTRN [TYPEPTRN [TYPEPTRN]]]\n"
 		  "                         list operators\n");
-	HELP0("  \\dO[S+] [PATTERN]      list collations\n");
-	HELP0("  \\dp[S]  [PATTERN]      list table, view, and sequence access privileges\n");
-	HELP0("  \\dP[itn+] [PATTERN]    list [only index/table] partitioned relations [n=nested]\n");
-	HELP0("  \\drds [ROLEPTRN [DBPTRN]] list per-database role settings\n");
-	HELP0("  \\drg[S] [PATTERN]      list role grants\n");
-	HELP0("  \\dRp[+] [PATTERN]      list replication publications\n");
-	HELP0("  \\dRs[+] [PATTERN]      list replication subscriptions\n");
-	HELP0("  \\ds[S+] [PATTERN]      list sequences\n");
-	HELP0("  \\dt[S+] [PATTERN]      list tables\n");
-	HELP0("  \\dT[S+] [PATTERN]      list data types\n");
-	HELP0("  \\du[S+] [PATTERN]      list roles\n");
-	HELP0("  \\dv[S+] [PATTERN]      list views\n");
-	HELP0("  \\dx[+]  [PATTERN]      list extensions\n");
-	HELP0("  \\dX     [PATTERN]      list extended statistics\n");
-	HELP0("  \\dy[+]  [PATTERN]      list event triggers\n");
-	HELP0("  \\l[+]   [PATTERN]      list databases\n");
-	HELP0("  \\sf[+]  FUNCNAME       show a function's definition\n");
-	HELP0("  \\sv[+]  VIEWNAME       show a view's definition\n");
-	HELP0("  \\z[S]   [PATTERN]      same as \\dp\n");
+	HELP0("  \\dO[Sx+] [PATTERN]     list collations\n");
+	HELP0("  \\dp[Sx]  [PATTERN]     list table, view, and sequence access privileges\n");
+	HELP0("  \\dP[itnx+] [PATTERN]   list [only index/table] partitioned relations [n=nested]\n");
+	HELP0("  \\drds[x] [ROLEPTRN [DBPTRN]] list per-database role settings\n");
+	HELP0("  \\drg[Sx] [PATTERN]     list role grants\n");
+	HELP0("  \\dRp[x+] [PATTERN]     list replication publications\n");
+	HELP0("  \\dRs[x+] [PATTERN]     list replication subscriptions\n");
+	HELP0("  \\ds[Sx+] [PATTERN]     list sequences\n");
+	HELP0("  \\dt[Sx+] [PATTERN]     list tables\n");
+	HELP0("  \\dT[Sx+] [PATTERN]     list data types\n");
+	HELP0("  \\du[Sx+] [PATTERN]     list roles\n");
+	HELP0("  \\dv[Sx+] [PATTERN]     list views\n");
+	HELP0("  \\dx[x+]  [PATTERN]     list extensions\n");
+	HELP0("  \\dX[x]   [PATTERN]     list extended statistics\n");
+	HELP0("  \\dy[x+]  [PATTERN]     list event triggers\n");
+	HELP0("  \\l[x+]   [PATTERN]     list databases\n");
+	HELP0("  \\sf[+]   FUNCNAME      show a function's definition\n");
+	HELP0("  \\sv[+]   VIEWNAME      show a view's definition\n");
+	HELP0("  \\z[Sx]   [PATTERN]     same as \\dp\n");
 	HELP0("\n");
 
 	HELP0("Large Objects\n");
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
new file mode 100644
index 36dc31c..e60db50
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -2841,6 +2841,19 @@ Owned by: public.psql_serial_tab.id
  pg_catalog | exp  | double precision | double precision    | func
  pg_catalog | exp  | numeric          | numeric             | func
 
+\dfx exp
+Schema              | pg_catalog
+Name                | exp
+Result data type    | double precision
+Argument data types | double precision
+Type                | func
+--------------------+-----------------
+Schema              | pg_catalog
+Name                | exp
+Result data type    | numeric
+Argument data types | numeric
+Type                | func
+
 \pset tuples_only false
 \pset expanded on
 \d psql_serial_tab_id_seq
@@ -3047,6 +3060,49 @@ Access method: heap
  tableam_display | view_heap_psql     | view              | regress_display_role | permanent   | 0 bytes | 
 (4 rows)
 
+-- \d with 'x' enables expanded mode, but only without a pattern
+\d+x tbl_heap
+                                 Table "tableam_display.tbl_heap"
+ Column |      Type      | Collation | Nullable | Default | Storage  | Stats target | Description 
+--------+----------------+-----------+----------+---------+----------+--------------+-------------
+ f1     | integer        |           |          |         | plain    |              | 
+ f2     | character(100) |           |          |         | extended |              | 
+
+\d+x
+List of relations
+-[ RECORD 1 ]---------------------
+Schema      | tableam_display
+Name        | mat_view_heap_psql
+Type        | materialized view
+Owner       | regress_display_role
+Persistence | permanent
+Size        | 0 bytes
+Description | 
+-[ RECORD 2 ]---------------------
+Schema      | tableam_display
+Name        | tbl_heap
+Type        | table
+Owner       | regress_display_role
+Persistence | permanent
+Size        | 0 bytes
+Description | 
+-[ RECORD 3 ]---------------------
+Schema      | tableam_display
+Name        | tbl_heap_psql
+Type        | table
+Owner       | regress_display_role
+Persistence | permanent
+Size        | 0 bytes
+Description | 
+-[ RECORD 4 ]---------------------
+Schema      | tableam_display
+Name        | view_heap_psql
+Type        | view
+Owner       | regress_display_role
+Persistence | permanent
+Size        | 0 bytes
+Description | 
+
 RESET ROLE;
 RESET search_path;
 DROP SCHEMA tableam_display CASCADE;
@@ -5233,6 +5289,30 @@ List of access methods
  btree | float_ops       | real                 | double precision      |      3 | in_range(real,real,double precision,boolean,boolean)
 (8 rows)
 
+\dApx+ btree time_ops
+List of support functions of operator families
+-[ RECORD 1 ]---------+---------------------------------------------------------------------------------
+AM                    | btree
+Operator family       | time_ops
+Registered left type  | time without time zone
+Registered right type | time without time zone
+Number                | 1
+Function              | time_cmp(time without time zone,time without time zone)
+-[ RECORD 2 ]---------+---------------------------------------------------------------------------------
+AM                    | btree
+Operator family       | time_ops
+Registered left type  | time without time zone
+Registered right type | time without time zone
+Number                | 4
+Function              | btequalimage(oid)
+-[ RECORD 3 ]---------+---------------------------------------------------------------------------------
+AM                    | btree
+Operator family       | time_ops
+Registered left type  | time without time zone
+Registered right type | interval
+Number                | 3
+Function              | in_range(time without time zone,time without time zone,interval,boolean,boolean)
+
 \dAp * pg_catalog.uuid_ops
                             List of support functions of operator families
   AM   | Operator family | Registered left type | Registered right type | Number |      Function      
@@ -6826,5 +6906,15 @@ CREATE TABLE defprivs (a int);
  public | defprivs | table | (default)         |                   | 
 (1 row)
 
+\zx defprivs
+Access privileges
+-[ RECORD 1 ]-----+----------
+Schema            | public
+Name              | defprivs
+Type              | table
+Access privileges | (default)
+Column privileges | 
+Policies          | 
+
 \pset null ''
 DROP TABLE defprivs;
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
new file mode 100644
index c5021fc..2bc7f95
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -498,6 +498,7 @@ create table psql_serial_tab (id serial)
 \d psql_serial_tab_id_seq
 \pset tuples_only true
 \df exp
+\dfx exp
 \pset tuples_only false
 \pset expanded on
 \d psql_serial_tab_id_seq
@@ -560,6 +561,9 @@ CREATE MATERIALIZED VIEW mat_view_heap_p
 \dv+
 \set HIDE_TABLEAM on
 \d+
+-- \d with 'x' enables expanded mode, but only without a pattern
+\d+x tbl_heap
+\d+x
 RESET ROLE;
 RESET search_path;
 DROP SCHEMA tableam_display CASCADE;
@@ -1309,6 +1313,7 @@ drop role regress_partitioning_role;
 \dAo+ btree float_ops
 \dAo * pg_catalog.jsonb_path_ops
 \dAp+ btree float_ops
+\dApx+ btree time_ops
 \dAp * pg_catalog.uuid_ops
 
 -- check \dconfig
@@ -1927,5 +1932,6 @@ ROLLBACK;
 CREATE TABLE defprivs (a int);
 \pset null '(default)'
 \z defprivs
+\zx defprivs
 \pset null ''
 DROP TABLE defprivs;

Reply via email to