I have applied a modified version of your patch, attached.  You missed
the cases where \x and \t also need to support boolean constants. The
documentation lumped them all together, and they should be consistent
with the \pset behavior.  You will see my change in the modified
do_pset() calls.

Thanks.

---------------------------------------------------------------------------

Chad Wagner wrote:
> This is a TODO item:
> 
>         o Allow psql \pset boolean variables to set to fixed values, rather
>           than toggle
> 
> 
> Basically allows for:
> test=# \pset expanded on
> Expanded display is on.
> test=# \pset footer off
> Default footer is off.
> test=# \pset footer
> Default footer is on.
> test=# \pset footer
> Default footer is off.
> test=# \pset footer
> Default footer is on.
> 
> 
> Basically the change is to check if value in do_pset is != NULL to call
> ParseVariableBool to get a true/false and set the value directly, of the
> second parameter is not provided then the "old logic" of toggling is
> supported.
> 
> The pset variables that are adjusted are:
> expanded
> numericlocale
> tuples_only
> pager (supports on/off/always now)
> footer

[ Attachment, skipping... ]

> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
> 
>                http://www.postgresql.org/docs/faq

-- 
  Bruce Momjian  <[EMAIL PROTECTED]>          http://momjian.us
  EnterpriseDB                               http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: doc/src/sgml/ref/psql-ref.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v
retrieving revision 1.187
diff -c -c -r1.187 psql-ref.sgml
*** doc/src/sgml/ref/psql-ref.sgml	23 Feb 2007 18:20:58 -0000	1.187
--- doc/src/sgml/ref/psql-ref.sgml	3 Mar 2007 17:11:53 -0000
***************
*** 1509,1519 ****
            <term><literal>expanded</literal> (or <literal>x</literal>)</term>
            <listitem>
            <para>
!           Toggles between regular and expanded format. When expanded
!           format is enabled, query results are displayed in two
!           columns, with the column name on the left and the data on
!           the right. This mode is useful if the data wouldn't fit on the
!           screen in the normal <quote>horizontal</quote> mode.
            </para>
  
            <para>
--- 1509,1522 ----
            <term><literal>expanded</literal> (or <literal>x</literal>)</term>
            <listitem>
            <para>
!           You can specify an optional second argument, if it is provided it
!           may be either <literal>on</literal> or <literal>off</literal>
!           which will enable or disable expanded mode.  If the second
!           argument is not provided then we will toggle between regular and
!           expanded format. When expanded format is enabled, query results
!           are displayed in two columns, with the column name on the left and
!           the data on the right. This mode is useful if the data wouldn't fit
!           on the screen in the normal <quote>horizontal</quote> mode.
            </para>
  
            <para>
***************
*** 1553,1560 ****
            <term><literal>footer</literal></term>
            <listitem>
            <para>
!           Toggles the display of the default footer <literal>(x
!           rows)</literal>.
            </para>
            </listitem>
            </varlistentry>
--- 1556,1566 ----
            <term><literal>footer</literal></term>
            <listitem>
            <para>
!           You can specify an optional second argument, if it is provided it
!           may be either <literal>on</literal> or <literal>off</literal>
!           which will enable or disable display of the default footer
!           <literal>(x rows)</literal>.  If the second argument is not
!           provided then we will toggle between on and off.
            </para>
            </listitem>
            </varlistentry>
***************
*** 1563,1571 ****
            <term><literal>numericlocale</literal></term>
            <listitem>
            <para>
!           Toggles the display of a locale-aware character to separate groups
!           of digits to the left of the decimal marker.  It also enables
!           a locale-aware decimal marker.
            </para>
            </listitem>
            </varlistentry>
--- 1569,1580 ----
            <term><literal>numericlocale</literal></term>
            <listitem>
            <para>
!           You can specify an optional second argument, if it is provided it
!           may be either <literal>on</literal> or <literal>off</literal>
!           which will enable or disable display of a locale-aware character
!           to seperate groups of digits to the left of the decimal marker.  If
!           the second argument is not provided then we will toggle between
!           on and off.
            </para>
            </listitem>
            </varlistentry>
***************
*** 1584,1593 ****
            <term><literal>tuples_only</literal> (or <literal>t</literal>)</term>
            <listitem>
            <para>
!           Toggles between tuples only and full display. Full display
!           shows extra information such as column headers, titles, and
!           various footers. In tuples only mode, only actual table data
!           is shown.
            </para>
            </listitem>
            </varlistentry>
--- 1593,1605 ----
            <term><literal>tuples_only</literal> (or <literal>t</literal>)</term>
            <listitem>
            <para>
!           You can specify an optional second argument, if it is provided it
!           may be either <literal>on</literal> or <literal>off</literal>
!           which will enable or display the tuples only mode.  If the
!           second argument is not provided then we will toggle between tuples
!           only and full display. Full display shows extra information such
!           as column headers, titles, and various footers. In tuples only
!           mode, only actual table data is shown.
            </para>
            </listitem>
            </varlistentry>
***************
*** 1636,1642 ****
            (<application>psql</> does not do a perfect job of estimating
            when to use the pager.) <literal>\pset pager</> turns the
            pager on and off. Pager can also be set to <literal>always</>,
!           which causes the pager to be always used.
            </para>
            </listitem>
            </varlistentry>
--- 1648,1657 ----
            (<application>psql</> does not do a perfect job of estimating
            when to use the pager.) <literal>\pset pager</> turns the
            pager on and off. Pager can also be set to <literal>always</>,
!           which causes the pager to be always used, or you can set the pager
!           to <literal>on</> which will enable the usage of the pager when
!           appropriate, or you can set the pager to <literal>off</> which
!           will disable the pager.
            </para>
            </listitem>
            </varlistentry>
Index: src/bin/psql/command.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/command.c,v
retrieving revision 1.178
diff -c -c -r1.178 command.c
*** src/bin/psql/command.c	23 Feb 2007 18:20:58 -0000	1.178
--- src/bin/psql/command.c	3 Mar 2007 17:11:54 -0000
***************
*** 863,869 ****
  
  	/* \t -- turn off headers and row count */
  	else if (strcmp(cmd, "t") == 0)
! 		success = do_pset("tuples_only", NULL, &pset.popt, pset.quiet);
  
  
  	/* \T -- define html <table ...> attributes */
--- 863,875 ----
  
  	/* \t -- turn off headers and row count */
  	else if (strcmp(cmd, "t") == 0)
! 	{
! 		char	   *opt = psql_scan_slash_option(scan_state,
! 												 OT_NORMAL, NULL, true);
! 
! 		success = do_pset("tuples_only", opt, &pset.popt, pset.quiet);
! 		free(opt);
! 	}
  
  
  	/* \T -- define html <table ...> attributes */
***************
*** 975,981 ****
  
  	/* \x -- toggle expanded table representation */
  	else if (strcmp(cmd, "x") == 0)
! 		success = do_pset("expanded", NULL, &pset.popt, pset.quiet);
  
  	/* \z -- list table rights (equivalent to \dp) */
  	else if (strcmp(cmd, "z") == 0)
--- 981,993 ----
  
  	/* \x -- toggle expanded table representation */
  	else if (strcmp(cmd, "x") == 0)
! 	{
! 		char	   *opt = psql_scan_slash_option(scan_state,
! 												 OT_NORMAL, NULL, true);
! 
! 		success = do_pset("expanded", opt, &pset.popt, pset.quiet);
! 		free(opt);
! 	}
  
  	/* \z -- list table rights (equivalent to \dp) */
  	else if (strcmp(cmd, "z") == 0)
***************
*** 1552,1558 ****
  	/* set expanded/vertical mode */
  	else if (strcmp(param, "x") == 0 || strcmp(param, "expanded") == 0 || strcmp(param, "vertical") == 0)
  	{
! 		popt->topt.expanded = !popt->topt.expanded;
  		if (!quiet)
  			printf(popt->topt.expanded
  				   ? _("Expanded display is on.\n")
--- 1564,1573 ----
  	/* set expanded/vertical mode */
  	else if (strcmp(param, "x") == 0 || strcmp(param, "expanded") == 0 || strcmp(param, "vertical") == 0)
  	{
! 		if (value)
! 			popt->topt.expanded = ParseVariableBool(value);
! 		else
! 			popt->topt.expanded = !popt->topt.expanded;
  		if (!quiet)
  			printf(popt->topt.expanded
  				   ? _("Expanded display is on.\n")
***************
*** 1562,1568 ****
  	/* locale-aware numeric output */
  	else if (strcmp(param, "numericlocale") == 0)
  	{
! 		popt->topt.numericLocale = !popt->topt.numericLocale;
  		if (!quiet)
  		{
  			if (popt->topt.numericLocale)
--- 1577,1586 ----
  	/* locale-aware numeric output */
  	else if (strcmp(param, "numericlocale") == 0)
  	{
! 		if (value)
! 			popt->topt.numericLocale = ParseVariableBool(value);
! 		else
! 			popt->topt.numericLocale = !popt->topt.numericLocale;
  		if (!quiet)
  		{
  			if (popt->topt.numericLocale)
***************
*** 1616,1622 ****
  	/* toggle between full and tuples-only format */
  	else if (strcmp(param, "t") == 0 || strcmp(param, "tuples_only") == 0)
  	{
! 		popt->topt.tuples_only = !popt->topt.tuples_only;
  		if (!quiet)
  		{
  			if (popt->topt.tuples_only)
--- 1634,1643 ----
  	/* toggle between full and tuples-only format */
  	else if (strcmp(param, "t") == 0 || strcmp(param, "tuples_only") == 0)
  	{
! 		if (value)
! 			popt->topt.tuples_only = ParseVariableBool(value);
! 		else
! 			popt->topt.tuples_only = !popt->topt.tuples_only;
  		if (!quiet)
  		{
  			if (popt->topt.tuples_only)
***************
*** 1667,1672 ****
--- 1688,1698 ----
  	{
  		if (value && pg_strcasecmp(value, "always") == 0)
  			popt->topt.pager = 2;
+ 		else if (value)
+ 			if (ParseVariableBool(value))
+ 				popt->topt.pager = 1;
+ 			else
+ 				popt->topt.pager = 0;
  		else if (popt->topt.pager == 1)
  			popt->topt.pager = 0;
  		else
***************
*** 1685,1691 ****
  	/* disable "(x rows)" footer */
  	else if (strcmp(param, "footer") == 0)
  	{
! 		popt->default_footer = !popt->default_footer;
  		if (!quiet)
  		{
  			if (popt->default_footer)
--- 1711,1720 ----
  	/* disable "(x rows)" footer */
  	else if (strcmp(param, "footer") == 0)
  	{
! 		if (value)
! 			popt->default_footer = ParseVariableBool(value);
! 		else
! 			popt->default_footer = !popt->default_footer;
  		if (!quiet)
  		{
  			if (popt->default_footer)
---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Reply via email to