The output from various psql meta-commands such as \df+ can be quite
wide, making it hard to read, and there is another patch [1] that will
make it even wider. The output is much more readable if expanded mode
is used, but it's somewhat inconvenient to keep turning that on and
off, if you don't want all other query output in expanded mode.

Attached is a rough patch that adds 'x' as an option to all \d* psql
meta-commands, which forces the output to be displayed in expanded
mode. So, for example, you can type \dfx or \dfx+ (or equivalently
\df+x) to show a list of functions in expanded mode.

This applies to all \d* meta-commands except a bare \d. That
limitation is necessary because \dx already means something else (list
extensions). In the case of \d with a pattern, this limitation isn't
really new, since that already always uses expanded=off for its output
regardless of the current \x setting. However, it does mean that you
can't use 'x' with \d without a pattern to get an expanded mode list
of all relations. However, the limitation only applies as long as
there isn't another character after the \d, so you can type \d+x and
it will work the same as \dtvmsE+x, listing all relations in expanded
mode. So in practice, this doesn't seem like such a bad limitation,
since you're much less likely to need expanded mode with \d without
'+'.

There are a couple of other similar meta-commands (\l and \z) that I
haven't looked at yet, but they should be easy to make work in the
same way, if people think this is useful.

Regards,
Dean

[1] 
https://www.postgresql.org/message-id/flat/20240701220817.483f9b645b95611f8b1f6...@sranhm.sraoss.co.jp
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 72f3347e53..b2ba7776f2 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -864,6 +864,13 @@ testdb=>
     same line.
     </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:
 
@@ -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 a
+        <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>
@@ -1342,7 +1361,7 @@ SELECT $1 \parse stmt1
       </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>
@@ -1357,7 +1376,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>
@@ -1380,7 +1399,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>
@@ -1403,7 +1422,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>
@@ -1427,7 +1446,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>
@@ -1449,7 +1468,7 @@ 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>
@@ -1465,7 +1484,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.
@@ -1483,7 +1502,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.
@@ -1502,7 +1521,7 @@ 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.
@@ -1517,7 +1536,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>,
@@ -1546,7 +1565,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
@@ -1563,7 +1582,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
@@ -1585,12 +1604,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>
@@ -1618,7 +1637,7 @@ 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
@@ -1634,7 +1653,7 @@ 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>).
@@ -1649,7 +1668,7 @@ 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
@@ -1672,7 +1691,7 @@ 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
@@ -1688,7 +1707,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>
@@ -1722,7 +1741,7 @@ 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.
@@ -1736,7 +1755,7 @@ 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.
@@ -1750,7 +1769,7 @@ 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.
@@ -1764,7 +1783,7 @@ 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.
@@ -1778,7 +1797,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.
@@ -1798,7 +1817,7 @@ 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
@@ -1811,7 +1830,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
@@ -1828,7 +1847,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>
@@ -1845,7 +1864,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.
@@ -1870,7 +1889,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.
@@ -1890,7 +1909,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
@@ -1914,7 +1933,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.
@@ -1947,7 +1966,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
@@ -1970,7 +1989,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
@@ -1990,7 +2009,7 @@ SELECT $1 \parse stmt1
 
 
       <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.
@@ -2004,7 +2023,7 @@ 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.
@@ -2018,7 +2037,7 @@ 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.
@@ -2035,7 +2054,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.
@@ -2054,7 +2073,7 @@ 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.
@@ -2068,7 +2087,7 @@ SELECT $1 \parse stmt1
       </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.
@@ -2090,7 +2109,7 @@ 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.
@@ -5386,6 +5405,30 @@ testdb=&gt; <userinput>\df int*pl * bigint</userinput>
 </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
index cd16f27947..462b23118f 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -850,6 +850,7 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
 		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 +859,16 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
 		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, and so the 'x' option cannot appear immediately
+		 * after the initial 'd'.
+		 */
+		save_expanded = pset.popt.topt.expanded;
+		if (strchr(&cmd[2], 'x'))
+			pset.popt.topt.expanded = 1;
+
 		switch (cmd[1])
 		{
 			case '\0':
@@ -873,13 +884,14 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
 				{
 					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 +953,7 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
 					case 'p':
 					case 't':
 					case 'w':
+					case 'x':
 						success = exec_command_dfo(scan_state, cmd, pattern,
 												   show_verbose, show_system);
 						break;
@@ -981,6 +994,7 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
 						case 't':
 						case 'i':
 						case 'n':
+						case 'x':
 							success = listPartitionedTables(&cmd[2], pattern, show_verbose);
 							break;
 						default:
@@ -1041,6 +1055,7 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
 				{
 					case '\0':
 					case '+':
+					case 'x':
 						success = listTSConfigs(pattern, show_verbose);
 						break;
 					case 'p':
@@ -1093,6 +1108,9 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
 				status = PSQL_CMD_UNKNOWN;
 		}
 
+		/* 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
index 2657abdc72..cbfb37e716 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -309,9 +309,9 @@ describeFunctions(const char *functypes, const char *func_pattern,
 	/* 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;
 	}
 

Reply via email to