Skip to content

Commit df910a5

Browse files
committedMar 3, 2007
Allow \pset and \x, \t to use boolean constants on/off, rather than just
toggle. Chad Wagner
1 parent bb8b5b8 commit df910a5

File tree

2 files changed

+67
-23
lines changed

2 files changed

+67
-23
lines changed
 

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.187 2007/02/23 18:20:58 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.188 2007/03/03 17:19:11 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -1509,11 +1509,14 @@ lo_import 152801
15091509
<term><literal>expanded</literal> (or <literal>x</literal>)</term>
15101510
<listitem>
15111511
<para>
1512-
Toggles between regular and expanded format. When expanded
1513-
format is enabled, query results are displayed in two
1514-
columns, with the column name on the left and the data on
1515-
the right. This mode is useful if the data wouldn't fit on the
1516-
screen in the normal <quote>horizontal</quote> mode.
1512+
You can specify an optional second argument, if it is provided it
1513+
may be either <literal>on</literal> or <literal>off</literal>
1514+
which will enable or disable expanded mode. If the second
1515+
argument is not provided then we will toggle between regular and
1516+
expanded format. When expanded format is enabled, query results
1517+
are displayed in two columns, with the column name on the left and
1518+
the data on the right. This mode is useful if the data wouldn't fit
1519+
on the screen in the normal <quote>horizontal</quote> mode.
15171520
</para>
15181521

15191522
<para>
@@ -1553,8 +1556,11 @@ lo_import 152801
15531556
<term><literal>footer</literal></term>
15541557
<listitem>
15551558
<para>
1556-
Toggles the display of the default footer <literal>(x
1557-
rows)</literal>.
1559+
You can specify an optional second argument, if it is provided it
1560+
may be either <literal>on</literal> or <literal>off</literal>
1561+
which will enable or disable display of the default footer
1562+
<literal>(x rows)</literal>. If the second argument is not
1563+
provided then we will toggle between on and off.
15581564
</para>
15591565
</listitem>
15601566
</varlistentry>
@@ -1563,9 +1569,12 @@ lo_import 152801
15631569
<term><literal>numericlocale</literal></term>
15641570
<listitem>
15651571
<para>
1566-
Toggles the display of a locale-aware character to separate groups
1567-
of digits to the left of the decimal marker. It also enables
1568-
a locale-aware decimal marker.
1572+
You can specify an optional second argument, if it is provided it
1573+
may be either <literal>on</literal> or <literal>off</literal>
1574+
which will enable or disable display of a locale-aware character
1575+
to seperate groups of digits to the left of the decimal marker. If
1576+
the second argument is not provided then we will toggle between
1577+
on and off.
15691578
</para>
15701579
</listitem>
15711580
</varlistentry>
@@ -1584,10 +1593,13 @@ lo_import 152801
15841593
<term><literal>tuples_only</literal> (or <literal>t</literal>)</term>
15851594
<listitem>
15861595
<para>
1587-
Toggles between tuples only and full display. Full display
1588-
shows extra information such as column headers, titles, and
1589-
various footers. In tuples only mode, only actual table data
1590-
is shown.
1596+
You can specify an optional second argument, if it is provided it
1597+
may be either <literal>on</literal> or <literal>off</literal>
1598+
which will enable or display the tuples only mode. If the
1599+
second argument is not provided then we will toggle between tuples
1600+
only and full display. Full display shows extra information such
1601+
as column headers, titles, and various footers. In tuples only
1602+
mode, only actual table data is shown.
15911603
</para>
15921604
</listitem>
15931605
</varlistentry>
@@ -1636,7 +1648,10 @@ lo_import 152801
16361648
(<application>psql</> does not do a perfect job of estimating
16371649
when to use the pager.) <literal>\pset pager</> turns the
16381650
pager on and off. Pager can also be set to <literal>always</>,
1639-
which causes the pager to be always used.
1651+
which causes the pager to be always used, or you can set the pager
1652+
to <literal>on</> which will enable the usage of the pager when
1653+
appropriate, or you can set the pager to <literal>off</> which
1654+
will disable the pager.
16401655
</para>
16411656
</listitem>
16421657
</varlistentry>

‎src/bin/psql/command.c

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.178 2007/02/23 18:20:58 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.179 2007/03/03 17:19:11 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -863,7 +863,13 @@ exec_command(const char *cmd,
863863

864864
/* \t -- turn off headers and row count */
865865
else if (strcmp(cmd, "t") == 0)
866-
success = do_pset("tuples_only", NULL, &pset.popt, pset.quiet);
866+
{
867+
char *opt = psql_scan_slash_option(scan_state,
868+
OT_NORMAL, NULL, true);
869+
870+
success = do_pset("tuples_only", opt, &pset.popt, pset.quiet);
871+
free(opt);
872+
}
867873

868874

869875
/* \T -- define html <table ...> attributes */
@@ -975,7 +981,13 @@ exec_command(const char *cmd,
975981

976982
/* \x -- toggle expanded table representation */
977983
else if (strcmp(cmd, "x") == 0)
978-
success = do_pset("expanded", NULL, &pset.popt, pset.quiet);
984+
{
985+
char *opt = psql_scan_slash_option(scan_state,
986+
OT_NORMAL, NULL, true);
987+
988+
success = do_pset("expanded", opt, &pset.popt, pset.quiet);
989+
free(opt);
990+
}
979991

980992
/* \z -- list table rights (equivalent to \dp) */
981993
else if (strcmp(cmd, "z") == 0)
@@ -1552,7 +1564,10 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
15521564
/* set expanded/vertical mode */
15531565
else if (strcmp(param, "x") == 0 || strcmp(param, "expanded") == 0 || strcmp(param, "vertical") == 0)
15541566
{
1555-
popt->topt.expanded = !popt->topt.expanded;
1567+
if (value)
1568+
popt->topt.expanded = ParseVariableBool(value);
1569+
else
1570+
popt->topt.expanded = !popt->topt.expanded;
15561571
if (!quiet)
15571572
printf(popt->topt.expanded
15581573
? _("Expanded display is on.\n")
@@ -1562,7 +1577,10 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
15621577
/* locale-aware numeric output */
15631578
else if (strcmp(param, "numericlocale") == 0)
15641579
{
1565-
popt->topt.numericLocale = !popt->topt.numericLocale;
1580+
if (value)
1581+
popt->topt.numericLocale = ParseVariableBool(value);
1582+
else
1583+
popt->topt.numericLocale = !popt->topt.numericLocale;
15661584
if (!quiet)
15671585
{
15681586
if (popt->topt.numericLocale)
@@ -1616,7 +1634,10 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
16161634
/* toggle between full and tuples-only format */
16171635
else if (strcmp(param, "t") == 0 || strcmp(param, "tuples_only") == 0)
16181636
{
1619-
popt->topt.tuples_only = !popt->topt.tuples_only;
1637+
if (value)
1638+
popt->topt.tuples_only = ParseVariableBool(value);
1639+
else
1640+
popt->topt.tuples_only = !popt->topt.tuples_only;
16201641
if (!quiet)
16211642
{
16221643
if (popt->topt.tuples_only)
@@ -1667,6 +1688,11 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
16671688
{
16681689
if (value && pg_strcasecmp(value, "always") == 0)
16691690
popt->topt.pager = 2;
1691+
else if (value)
1692+
if (ParseVariableBool(value))
1693+
popt->topt.pager = 1;
1694+
else
1695+
popt->topt.pager = 0;
16701696
else if (popt->topt.pager == 1)
16711697
popt->topt.pager = 0;
16721698
else
@@ -1685,7 +1711,10 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
16851711
/* disable "(x rows)" footer */
16861712
else if (strcmp(param, "footer") == 0)
16871713
{
1688-
popt->default_footer = !popt->default_footer;
1714+
if (value)
1715+
popt->default_footer = ParseVariableBool(value);
1716+
else
1717+
popt->default_footer = !popt->default_footer;
16891718
if (!quiet)
16901719
{
16911720
if (popt->default_footer)

0 commit comments

Comments
 (0)