Thread

  1. PATCH: psql boolean display

    Phil Sorber <phil@omniti.com> — 2012-08-19T16:02:31Z

    Hello all,
    
    I am providing a patch to allow you to change the output of a boolean
    value in psql much like you can do with NULL. A client requested this
    feature and we thought it may appeal to someone else in the community.
    
    The patch includes updated docs and a regression test. The code
    changes themselves are pretty simple and straightforward.
    
    Example from the regression test:
    
    SELECT true, false;
     bool | bool
    ------+------
     t    | f
    (1 row)
    
    \pset booltrue 'foo'
    \pset boolfalse 'bar'
    SELECT true, false;
     bool | bool
    ------+------
     foo  | bar
    (1 row)
    
    \pset booltrue 't'
    \pset boolfalse 'f'
    SELECT true, false;
     bool | bool
    ------+------
     t    | f
    (1 row)
    
    As always, comments welcome.
    
    Thanks.
    
  2. Re: PATCH: psql boolean display

    Robert Haas <robertmhaas@gmail.com> — 2012-08-20T19:42:28Z

    On Sun, Aug 19, 2012 at 12:02 PM, Phil Sorber <phil@omniti.com> wrote:
    > I am providing a patch to allow you to change the output of a boolean
    > value in psql much like you can do with NULL. A client requested this
    > feature and we thought it may appeal to someone else in the community.
    >
    > The patch includes updated docs and a regression test. The code
    > changes themselves are pretty simple and straightforward.
    >
    > Example from the regression test:
    >
    > SELECT true, false;
    >  bool | bool
    > ------+------
    >  t    | f
    > (1 row)
    >
    > \pset booltrue 'foo'
    > \pset boolfalse 'bar'
    > SELECT true, false;
    >  bool | bool
    > ------+------
    >  foo  | bar
    > (1 row)
    >
    > \pset booltrue 't'
    > \pset boolfalse 'f'
    > SELECT true, false;
    >  bool | bool
    > ------+------
    >  t    | f
    > (1 row)
    >
    > As always, comments welcome.
    
    Why not just do it in the SQL?
    
    SELECT CASE WHEN whatever THEN 'foo' ELSE 'bar' END AS whatever;
    
    -- 
    Robert Haas
    EnterpriseDB: http://www.enterprisedb.com
    The Enterprise PostgreSQL Company
    
    
    
  3. Re: PATCH: psql boolean display

    Pavel Stehule <pavel.stehule@gmail.com> — 2012-08-20T21:10:44Z

    2012/8/20 Robert Haas <robertmhaas@gmail.com>:
    > On Sun, Aug 19, 2012 at 12:02 PM, Phil Sorber <phil@omniti.com> wrote:
    >> I am providing a patch to allow you to change the output of a boolean
    >> value in psql much like you can do with NULL. A client requested this
    >> feature and we thought it may appeal to someone else in the community.
    >>
    >> The patch includes updated docs and a regression test. The code
    >> changes themselves are pretty simple and straightforward.
    >>
    >> Example from the regression test:
    >>
    >> SELECT true, false;
    >>  bool | bool
    >> ------+------
    >>  t    | f
    >> (1 row)
    >>
    >> \pset booltrue 'foo'
    >> \pset boolfalse 'bar'
    >> SELECT true, false;
    >>  bool | bool
    >> ------+------
    >>  foo  | bar
    >> (1 row)
    >>
    >> \pset booltrue 't'
    >> \pset boolfalse 'f'
    >> SELECT true, false;
    >>  bool | bool
    >> ------+------
    >>  t    | f
    >> (1 row)
    >>
    >> As always, comments welcome.
    >
    > Why not just do it in the SQL?
    >
    > SELECT CASE WHEN whatever THEN 'foo' ELSE 'bar' END AS whatever;
    
    I understand this motivation - although I was more happy with server
    side solution.
    
    Regards
    
    Pavel Stehule
    
    >
    > --
    > Robert Haas
    > EnterpriseDB: http://www.enterprisedb.com
    > The Enterprise PostgreSQL Company
    >
    >
    > --
    > Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
    > To make changes to your subscription:
    > http://www.postgresql.org/mailpref/pgsql-hackers
    
    
    
  4. Re: PATCH: psql boolean display

    Phil Sorber <phil@omniti.com> — 2012-08-20T21:19:11Z

    On Aug 20, 2012 5:11 PM, "Pavel Stehule" <pavel.stehule@gmail.com> wrote:
    >
    > 2012/8/20 Robert Haas <robertmhaas@gmail.com>:
    > > On Sun, Aug 19, 2012 at 12:02 PM, Phil Sorber <phil@omniti.com> wrote:
    > >> I am providing a patch to allow you to change the output of a boolean
    > >> value in psql much like you can do with NULL. A client requested this
    > >> feature and we thought it may appeal to someone else in the community.
    > >>
    > >> The patch includes updated docs and a regression test. The code
    > >> changes themselves are pretty simple and straightforward.
    > >>
    > >> Example from the regression test:
    > >>
    > >> SELECT true, false;
    > >>  bool | bool
    > >> ------+------
    > >>  t    | f
    > >> (1 row)
    > >>
    > >> \pset booltrue 'foo'
    > >> \pset boolfalse 'bar'
    > >> SELECT true, false;
    > >>  bool | bool
    > >> ------+------
    > >>  foo  | bar
    > >> (1 row)
    > >>
    > >> \pset booltrue 't'
    > >> \pset boolfalse 'f'
    > >> SELECT true, false;
    > >>  bool | bool
    > >> ------+------
    > >>  t    | f
    > >> (1 row)
    > >>
    > >> As always, comments welcome.
    > >
    > > Why not just do it in the SQL?
    > >
    > > SELECT CASE WHEN whatever THEN 'foo' ELSE 'bar' END AS whatever;
    >
    > I understand this motivation - although I was more happy with server
    > side solution.
    >
    
    Was a server side implementation submitted before? I can change it, but I
    did it on the client side like the null display was done.
    
    > Regards
    >
    > Pavel Stehule
    >
    > >
    > > --
    > > Robert Haas
    > > EnterpriseDB: http://www.enterprisedb.com
    > > The Enterprise PostgreSQL Company
    > >
    > >
    > > --
    > > Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
    > > To make changes to your subscription:
    > > http://www.postgresql.org/mailpref/pgsql-hackers
    
  5. Re: PATCH: psql boolean display

    Phil Sorber <phil@omniti.com> — 2012-08-20T21:31:19Z

    On Aug 20, 2012 5:19 PM, "Phil Sorber" <phil@omniti.com> wrote:
    >
    > On Aug 20, 2012 5:11 PM, "Pavel Stehule" <pavel.stehule@gmail.com> wrote:
    > >
    > > 2012/8/20 Robert Haas <robertmhaas@gmail.com>:
    > > > On Sun, Aug 19, 2012 at 12:02 PM, Phil Sorber <phil@omniti.com> wrote:
    > > >> I am providing a patch to allow you to change the output of a boolean
    > > >> value in psql much like you can do with NULL. A client requested this
    > > >> feature and we thought it may appeal to someone else in the
    community.
    > > >>
    > > >> The patch includes updated docs and a regression test. The code
    > > >> changes themselves are pretty simple and straightforward.
    > > >>
    > > >> Example from the regression test:
    > > >>
    > > >> SELECT true, false;
    > > >>  bool | bool
    > > >> ------+------
    > > >>  t    | f
    > > >> (1 row)
    > > >>
    > > >> \pset booltrue 'foo'
    > > >> \pset boolfalse 'bar'
    > > >> SELECT true, false;
    > > >>  bool | bool
    > > >> ------+------
    > > >>  foo  | bar
    > > >> (1 row)
    > > >>
    > > >> \pset booltrue 't'
    > > >> \pset boolfalse 'f'
    > > >> SELECT true, false;
    > > >>  bool | bool
    > > >> ------+------
    > > >>  t    | f
    > > >> (1 row)
    > > >>
    > > >> As always, comments welcome.
    > > >
    > > > Why not just do it in the SQL?
    > > >
    > > > SELECT CASE WHEN whatever THEN 'foo' ELSE 'bar' END AS whatever;
    > >
    > > I understand this motivation - although I was more happy with server
    > > side solution.
    > >
    >
    > Was a server side implementation submitted before? I can change it, but I
    did it on the client side like the null display was done.
    
    Or how about both?
    
    >
    > > Regards
    > >
    > > Pavel Stehule
    > >
    > > >
    > > > --
    > > > Robert Haas
    > > > EnterpriseDB: http://www.enterprisedb.com
    > > > The Enterprise PostgreSQL Company
    > > >
    > > >
    > > > --
    > > > Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
    > > > To make changes to your subscription:
    > > > http://www.postgresql.org/mailpref/pgsql-hackers
    
  6. Re: PATCH: psql boolean display

    Thom Brown <thom@linux.com> — 2012-08-20T21:54:42Z

    On 20 August 2012 22:10, Pavel Stehule <pavel.stehule@gmail.com> wrote:
    > 2012/8/20 Robert Haas <robertmhaas@gmail.com>:
    >> On Sun, Aug 19, 2012 at 12:02 PM, Phil Sorber <phil@omniti.com> wrote:
    >>> I am providing a patch to allow you to change the output of a boolean
    >>> value in psql much like you can do with NULL. A client requested this
    >>> feature and we thought it may appeal to someone else in the community.
    >>>
    >>> The patch includes updated docs and a regression test. The code
    >>> changes themselves are pretty simple and straightforward.
    >>>
    >>> Example from the regression test:
    >>>
    >>> SELECT true, false;
    >>>  bool | bool
    >>> ------+------
    >>>  t    | f
    >>> (1 row)
    >>>
    >>> \pset booltrue 'foo'
    >>> \pset boolfalse 'bar'
    >>> SELECT true, false;
    >>>  bool | bool
    >>> ------+------
    >>>  foo  | bar
    >>> (1 row)
    >>>
    >>> \pset booltrue 't'
    >>> \pset boolfalse 'f'
    >>> SELECT true, false;
    >>>  bool | bool
    >>> ------+------
    >>>  t    | f
    >>> (1 row)
    >>>
    >>> As always, comments welcome.
    >>
    >> Why not just do it in the SQL?
    >>
    >> SELECT CASE WHEN whatever THEN 'foo' ELSE 'bar' END AS whatever;
    >
    > I understand this motivation - although I was more happy with server
    > side solution.
    
    Wouldn't a server-side solution risk breaking many things that depends
    on such a representation?  You wouldn't be able to pick and choose
    what comes out of the server on a per-application basis unless you use
    cumbersome CASE clauses in every query that returns boolean data.
    
    It sounds like keeping it at the application level is the least
    disruptive, and there is a precedent for such changes, such as NULL
    representation.
    
    -- 
    Thom
    
    
    
  7. Re: PATCH: psql boolean display

    Thom Brown <thom@linux.com> — 2012-08-20T21:56:12Z

    On 20 August 2012 22:31, Phil Sorber <phil@omniti.com> wrote:
    > On Aug 20, 2012 5:19 PM, "Phil Sorber" <phil@omniti.com> wrote:
    >>
    >> On Aug 20, 2012 5:11 PM, "Pavel Stehule" <pavel.stehule@gmail.com> wrote:
    >> >
    >> > 2012/8/20 Robert Haas <robertmhaas@gmail.com>:
    >> > > On Sun, Aug 19, 2012 at 12:02 PM, Phil Sorber <phil@omniti.com> wrote:
    >> > >> I am providing a patch to allow you to change the output of a boolean
    >> > >> value in psql much like you can do with NULL. A client requested this
    >> > >> feature and we thought it may appeal to someone else in the
    >> > >> community.
    >> > >>
    >> > >> The patch includes updated docs and a regression test. The code
    >> > >> changes themselves are pretty simple and straightforward.
    >> > >>
    >> > >> Example from the regression test:
    >> > >>
    >> > >> SELECT true, false;
    >> > >>  bool | bool
    >> > >> ------+------
    >> > >>  t    | f
    >> > >> (1 row)
    >> > >>
    >> > >> \pset booltrue 'foo'
    >> > >> \pset boolfalse 'bar'
    >> > >> SELECT true, false;
    >> > >>  bool | bool
    >> > >> ------+------
    >> > >>  foo  | bar
    >> > >> (1 row)
    >> > >>
    >> > >> \pset booltrue 't'
    >> > >> \pset boolfalse 'f'
    >> > >> SELECT true, false;
    >> > >>  bool | bool
    >> > >> ------+------
    >> > >>  t    | f
    >> > >> (1 row)
    >> > >>
    >> > >> As always, comments welcome.
    >> > >
    >> > > Why not just do it in the SQL?
    >> > >
    >> > > SELECT CASE WHEN whatever THEN 'foo' ELSE 'bar' END AS whatever;
    >> >
    >> > I understand this motivation - although I was more happy with server
    >> > side solution.
    >> >
    >>
    >> Was a server side implementation submitted before? I can change it, but I
    >> did it on the client side like the null display was done.
    >
    > Or how about both?
    
    Surely one would break the other?
    
    -- 
    Thom
    
    
    
  8. Re: PATCH: psql boolean display

    Pavel Stehule <pavel.stehule@gmail.com> — 2012-08-20T22:00:35Z

    2012/8/20 Thom Brown <thom@linux.com>:
    > On 20 August 2012 22:10, Pavel Stehule <pavel.stehule@gmail.com> wrote:
    >> 2012/8/20 Robert Haas <robertmhaas@gmail.com>:
    >>> On Sun, Aug 19, 2012 at 12:02 PM, Phil Sorber <phil@omniti.com> wrote:
    >>>> I am providing a patch to allow you to change the output of a boolean
    >>>> value in psql much like you can do with NULL. A client requested this
    >>>> feature and we thought it may appeal to someone else in the community.
    >>>>
    >>>> The patch includes updated docs and a regression test. The code
    >>>> changes themselves are pretty simple and straightforward.
    >>>>
    >>>> Example from the regression test:
    >>>>
    >>>> SELECT true, false;
    >>>>  bool | bool
    >>>> ------+------
    >>>>  t    | f
    >>>> (1 row)
    >>>>
    >>>> \pset booltrue 'foo'
    >>>> \pset boolfalse 'bar'
    >>>> SELECT true, false;
    >>>>  bool | bool
    >>>> ------+------
    >>>>  foo  | bar
    >>>> (1 row)
    >>>>
    >>>> \pset booltrue 't'
    >>>> \pset boolfalse 'f'
    >>>> SELECT true, false;
    >>>>  bool | bool
    >>>> ------+------
    >>>>  t    | f
    >>>> (1 row)
    >>>>
    >>>> As always, comments welcome.
    >>>
    >>> Why not just do it in the SQL?
    >>>
    >>> SELECT CASE WHEN whatever THEN 'foo' ELSE 'bar' END AS whatever;
    >>
    >> I understand this motivation - although I was more happy with server
    >> side solution.
    >
    > Wouldn't a server-side solution risk breaking many things that depends
    > on such a representation?  You wouldn't be able to pick and choose
    > what comes out of the server on a per-application basis unless you use
    > cumbersome CASE clauses in every query that returns boolean data.
    >
    > It sounds like keeping it at the application level is the least
    > disruptive, and there is a precedent for such changes, such as NULL
    > representation.
    
    It is similar to datetime formatting or to number formatting.
    
    Sometimes it is issue for some untyped languages because 't' or 'f'
    has not adequate sense - but it is unfriendly when somebody working
    with console. console based solution like proposed patch is probably
    the most less evil solution. Using 't' and 'f' was not a best idea.
    
    
    >
    > --
    > Thom
    
    
    
  9. Re: PATCH: psql boolean display

    Phil Sorber <phil@omniti.com> — 2012-08-20T22:06:30Z

    On Aug 20, 2012 5:56 PM, "Thom Brown" <thom@linux.com> wrote:
    >
    > On 20 August 2012 22:31, Phil Sorber <phil@omniti.com> wrote:
    > > On Aug 20, 2012 5:19 PM, "Phil Sorber" <phil@omniti.com> wrote:
    > >>
    > >> On Aug 20, 2012 5:11 PM, "Pavel Stehule" <pavel.stehule@gmail.com>
    wrote:
    > >> >
    > >> > 2012/8/20 Robert Haas <robertmhaas@gmail.com>:
    > >> > > On Sun, Aug 19, 2012 at 12:02 PM, Phil Sorber <phil@omniti.com>
    wrote:
    > >> > >> I am providing a patch to allow you to change the output of a
    boolean
    > >> > >> value in psql much like you can do with NULL. A client requested
    this
    > >> > >> feature and we thought it may appeal to someone else in the
    > >> > >> community.
    > >> > >>
    > >> > >> The patch includes updated docs and a regression test. The code
    > >> > >> changes themselves are pretty simple and straightforward.
    > >> > >>
    > >> > >> Example from the regression test:
    > >> > >>
    > >> > >> SELECT true, false;
    > >> > >>  bool | bool
    > >> > >> ------+------
    > >> > >>  t    | f
    > >> > >> (1 row)
    > >> > >>
    > >> > >> \pset booltrue 'foo'
    > >> > >> \pset boolfalse 'bar'
    > >> > >> SELECT true, false;
    > >> > >>  bool | bool
    > >> > >> ------+------
    > >> > >>  foo  | bar
    > >> > >> (1 row)
    > >> > >>
    > >> > >> \pset booltrue 't'
    > >> > >> \pset boolfalse 'f'
    > >> > >> SELECT true, false;
    > >> > >>  bool | bool
    > >> > >> ------+------
    > >> > >>  t    | f
    > >> > >> (1 row)
    > >> > >>
    > >> > >> As always, comments welcome.
    > >> > >
    > >> > > Why not just do it in the SQL?
    > >> > >
    > >> > > SELECT CASE WHEN whatever THEN 'foo' ELSE 'bar' END AS whatever;
    > >> >
    > >> > I understand this motivation - although I was more happy with server
    > >> > side solution.
    > >> >
    > >>
    > >> Was a server side implementation submitted before? I can change it,
    but I
    > >> did it on the client side like the null display was done.
    > >
    > > Or how about both?
    >
    > Surely one would break the other?
    >
    
    If using both.
    
    > --
    > Thom
    
  10. Re: PATCH: psql boolean display

    Thom Brown <thom@linux.com> — 2012-08-20T22:08:14Z

    On 20 August 2012 23:06, Phil Sorber <phil@omniti.com> wrote:
    >
    > On Aug 20, 2012 5:56 PM, "Thom Brown" <thom@linux.com> wrote:
    >>
    >> On 20 August 2012 22:31, Phil Sorber <phil@omniti.com> wrote:
    >> > On Aug 20, 2012 5:19 PM, "Phil Sorber" <phil@omniti.com> wrote:
    >> >>
    >> >> On Aug 20, 2012 5:11 PM, "Pavel Stehule" <pavel.stehule@gmail.com>
    >> >> wrote:
    >> >> >
    >> >> > 2012/8/20 Robert Haas <robertmhaas@gmail.com>:
    >> >> > > On Sun, Aug 19, 2012 at 12:02 PM, Phil Sorber <phil@omniti.com>
    >> >> > > wrote:
    >> >> > >> I am providing a patch to allow you to change the output of a
    >> >> > >> boolean
    >> >> > >> value in psql much like you can do with NULL. A client requested
    >> >> > >> this
    >> >> > >> feature and we thought it may appeal to someone else in the
    >> >> > >> community.
    >> >> > >>
    >> >> > >> The patch includes updated docs and a regression test. The code
    >> >> > >> changes themselves are pretty simple and straightforward.
    >> >> > >>
    >> >> > >> Example from the regression test:
    >> >> > >>
    >> >> > >> SELECT true, false;
    >> >> > >>  bool | bool
    >> >> > >> ------+------
    >> >> > >>  t    | f
    >> >> > >> (1 row)
    >> >> > >>
    >> >> > >> \pset booltrue 'foo'
    >> >> > >> \pset boolfalse 'bar'
    >> >> > >> SELECT true, false;
    >> >> > >>  bool | bool
    >> >> > >> ------+------
    >> >> > >>  foo  | bar
    >> >> > >> (1 row)
    >> >> > >>
    >> >> > >> \pset booltrue 't'
    >> >> > >> \pset boolfalse 'f'
    >> >> > >> SELECT true, false;
    >> >> > >>  bool | bool
    >> >> > >> ------+------
    >> >> > >>  t    | f
    >> >> > >> (1 row)
    >> >> > >>
    >> >> > >> As always, comments welcome.
    >> >> > >
    >> >> > > Why not just do it in the SQL?
    >> >> > >
    >> >> > > SELECT CASE WHEN whatever THEN 'foo' ELSE 'bar' END AS whatever;
    >> >> >
    >> >> > I understand this motivation - although I was more happy with server
    >> >> > side solution.
    >> >> >
    >> >>
    >> >> Was a server side implementation submitted before? I can change it, but
    >> >> I
    >> >> did it on the client side like the null display was done.
    >> >
    >> > Or how about both?
    >>
    >> Surely one would break the other?
    >>
    >
    > If using both.
    
    Yes. :)
    
    -- 
    Thom
    
    
    
  11. Re: PATCH: psql boolean display

    Gurjeet Singh <singh.gurjeet@gmail.com> — 2012-08-20T22:08:58Z

    On Mon, Aug 20, 2012 at 5:54 PM, Thom Brown <thom@linux.com> wrote:
    
    > On 20 August 2012 22:10, Pavel Stehule <pavel.stehule@gmail.com> wrote:
    > > 2012/8/20 Robert Haas <robertmhaas@gmail.com>:
    > >> On Sun, Aug 19, 2012 at 12:02 PM, Phil Sorber <phil@omniti.com> wrote:
    > >>> I am providing a patch to allow you to change the output of a boolean
    > >>> value in psql much like you can do with NULL. A client requested this
    > >>> feature and we thought it may appeal to someone else in the community.
    > >>>
    > >>> The patch includes updated docs and a regression test. The code
    > >>> changes themselves are pretty simple and straightforward.
    > >>>
    > >>> Example from the regression test:
    > >>>
    > >>> SELECT true, false;
    > >>>  bool | bool
    > >>> ------+------
    > >>>  t    | f
    > >>> (1 row)
    > >>>
    > >>> \pset booltrue 'foo'
    > >>> \pset boolfalse 'bar'
    > >>> SELECT true, false;
    > >>>  bool | bool
    > >>> ------+------
    > >>>  foo  | bar
    > >>> (1 row)
    > >>>
    > >>> \pset booltrue 't'
    > >>> \pset boolfalse 'f'
    > >>> SELECT true, false;
    > >>>  bool | bool
    > >>> ------+------
    > >>>  t    | f
    > >>> (1 row)
    > >>>
    > >>> As always, comments welcome.
    > >>
    > >> Why not just do it in the SQL?
    > >>
    > >> SELECT CASE WHEN whatever THEN 'foo' ELSE 'bar' END AS whatever;
    > >
    > > I understand this motivation - although I was more happy with server
    > > side solution.
    >
    > Wouldn't a server-side solution risk breaking many things that depends
    > on such a representation?  You wouldn't be able to pick and choose
    > what comes out of the server on a per-application basis unless you use
    > cumbersome CASE clauses in every query that returns boolean data.
    >
    > It sounds like keeping it at the application level is the least
    > disruptive, and there is a precedent for such changes, such as NULL
    > representation.
    
    
    On occasions I have wanted psql to emit the full 'True'/'False' words
    instead of cryptic one-letter t/f, which can get lost on long rows that get
    wrapped around on screen. Writing long-winded CASE expressions to get the
    effect is too much for small ad-hoc queries.
    
    I thought of inventing a data type whose out-function would emit these
    strings, and tack a ::mybool to the expression I want modified. But that
    would break the applications if somebody pasted the same  query in an
    application (JDBC or some such that understands boolean) and expected a
    boolean data type instead of a text output of an expression.
    
    I think there's a merit to psql supporting this feature, because psql is
    most commonly used for ad-hoc interactive use, and true/false is more human
    consumable than t/f (I have had a Java developer ask me what was that 't'
    value in the resultset in psql).
    
    -- 
    Gurjeet Singh
    
  12. Re: PATCH: psql boolean display

    Phil Sorber <phil@omniti.com> — 2012-08-20T22:16:37Z

    On Aug 20, 2012 6:08 PM, "Thom Brown" <thom@linux.com> wrote:
    >
    > On 20 August 2012 23:06, Phil Sorber <phil@omniti.com> wrote:
    > >
    > > On Aug 20, 2012 5:56 PM, "Thom Brown" <thom@linux.com> wrote:
    > >>
    > >> On 20 August 2012 22:31, Phil Sorber <phil@omniti.com> wrote:
    > >> > On Aug 20, 2012 5:19 PM, "Phil Sorber" <phil@omniti.com> wrote:
    > >> >>
    > >> >> On Aug 20, 2012 5:11 PM, "Pavel Stehule" <pavel.stehule@gmail.com>
    > >> >> wrote:
    > >> >> >
    > >> >> > 2012/8/20 Robert Haas <robertmhaas@gmail.com>:
    > >> >> > > On Sun, Aug 19, 2012 at 12:02 PM, Phil Sorber <phil@omniti.com>
    > >> >> > > wrote:
    > >> >> > >> I am providing a patch to allow you to change the output of a
    > >> >> > >> boolean
    > >> >> > >> value in psql much like you can do with NULL. A client
    requested
    > >> >> > >> this
    > >> >> > >> feature and we thought it may appeal to someone else in the
    > >> >> > >> community.
    > >> >> > >>
    > >> >> > >> The patch includes updated docs and a regression test. The code
    > >> >> > >> changes themselves are pretty simple and straightforward.
    > >> >> > >>
    > >> >> > >> Example from the regression test:
    > >> >> > >>
    > >> >> > >> SELECT true, false;
    > >> >> > >>  bool | bool
    > >> >> > >> ------+------
    > >> >> > >>  t    | f
    > >> >> > >> (1 row)
    > >> >> > >>
    > >> >> > >> \pset booltrue 'foo'
    > >> >> > >> \pset boolfalse 'bar'
    > >> >> > >> SELECT true, false;
    > >> >> > >>  bool | bool
    > >> >> > >> ------+------
    > >> >> > >>  foo  | bar
    > >> >> > >> (1 row)
    > >> >> > >>
    > >> >> > >> \pset booltrue 't'
    > >> >> > >> \pset boolfalse 'f'
    > >> >> > >> SELECT true, false;
    > >> >> > >>  bool | bool
    > >> >> > >> ------+------
    > >> >> > >>  t    | f
    > >> >> > >> (1 row)
    > >> >> > >>
    > >> >> > >> As always, comments welcome.
    > >> >> > >
    > >> >> > > Why not just do it in the SQL?
    > >> >> > >
    > >> >> > > SELECT CASE WHEN whatever THEN 'foo' ELSE 'bar' END AS whatever;
    > >> >> >
    > >> >> > I understand this motivation - although I was more happy with
    server
    > >> >> > side solution.
    > >> >> >
    > >> >>
    > >> >> Was a server side implementation submitted before? I can change it,
    but
    > >> >> I
    > >> >> did it on the client side like the null display was done.
    > >> >
    > >> > Or how about both?
    > >>
    > >> Surely one would break the other?
    > >>
    > >
    > > If using both.
    >
    > Yes. :)
    
    Really server would override client.
    
    >
    > --
    > Thom
    
  13. Re: PATCH: psql boolean display

    Kevin Grittner <kevin.grittner@wicourts.gov> — 2012-08-20T22:28:04Z

    Gurjeet Singh <singh.gurjeet@gmail.com> wrote:
     
    > On occasions I have wanted psql to emit the full 'True'/'False'
    > words instead of cryptic one-letter t/f, which can get lost on
    > long rows that get wrapped around on screen. Writing long-winded
    > CASE expressions to get the effect is too much for small ad-hoc
    > queries.
    > 
    > I thought of inventing a data type whose out-function would emit
    > these strings, and tack a ::mybool to the expression I want
    > modified. But that would break the applications if somebody pasted
    > the same  query in an application (JDBC or some such that
    > understands boolean) and expected a boolean data type instead of a
    > text output of an expression.
     
    The type itself does output true/false; it's just psql that uses
    t/f.
     
    test=# select 'true'::boolean::text;
     text 
    ------
     true
    (1 row)
     
    test=# select 'false'::boolean::text;
     text  
    -------
     false
    (1 row)
     
    That has always seemed quite odd (and occasionally inconvenient) to
    me.
     
    -Kevin
    
    
    
  14. Re: PATCH: psql boolean display

    Thom Brown <thom@linux.com> — 2012-08-20T22:30:35Z

    On 20 August 2012 23:16, Phil Sorber <phil@omniti.com> wrote:
    >
    > On Aug 20, 2012 6:08 PM, "Thom Brown" <thom@linux.com> wrote:
    >>
    >> On 20 August 2012 23:06, Phil Sorber <phil@omniti.com> wrote:
    >> >
    >> > On Aug 20, 2012 5:56 PM, "Thom Brown" <thom@linux.com> wrote:
    >> >>
    >> >> On 20 August 2012 22:31, Phil Sorber <phil@omniti.com> wrote:
    >> >> > On Aug 20, 2012 5:19 PM, "Phil Sorber" <phil@omniti.com> wrote:
    >> >> >>
    >> >> >> On Aug 20, 2012 5:11 PM, "Pavel Stehule" <pavel.stehule@gmail.com>
    >> >> >> wrote:
    >> >> >> >
    >> >> >> > 2012/8/20 Robert Haas <robertmhaas@gmail.com>:
    >> >> >> > > On Sun, Aug 19, 2012 at 12:02 PM, Phil Sorber <phil@omniti.com>
    >> >> >> > > wrote:
    >> >> >> > >> I am providing a patch to allow you to change the output of a
    >> >> >> > >> boolean
    >> >> >> > >> value in psql much like you can do with NULL. A client
    >> >> >> > >> requested
    >> >> >> > >> this
    >> >> >> > >> feature and we thought it may appeal to someone else in the
    >> >> >> > >> community.
    >> >> >> > >>
    >> >> >> > >> The patch includes updated docs and a regression test. The code
    >> >> >> > >> changes themselves are pretty simple and straightforward.
    >> >> >> > >>
    >> >> >> > >> Example from the regression test:
    >> >> >> > >>
    >> >> >> > >> SELECT true, false;
    >> >> >> > >>  bool | bool
    >> >> >> > >> ------+------
    >> >> >> > >>  t    | f
    >> >> >> > >> (1 row)
    >> >> >> > >>
    >> >> >> > >> \pset booltrue 'foo'
    >> >> >> > >> \pset boolfalse 'bar'
    >> >> >> > >> SELECT true, false;
    >> >> >> > >>  bool | bool
    >> >> >> > >> ------+------
    >> >> >> > >>  foo  | bar
    >> >> >> > >> (1 row)
    >> >> >> > >>
    >> >> >> > >> \pset booltrue 't'
    >> >> >> > >> \pset boolfalse 'f'
    >> >> >> > >> SELECT true, false;
    >> >> >> > >>  bool | bool
    >> >> >> > >> ------+------
    >> >> >> > >>  t    | f
    >> >> >> > >> (1 row)
    >> >> >> > >>
    >> >> >> > >> As always, comments welcome.
    >> >> >> > >
    >> >> >> > > Why not just do it in the SQL?
    >> >> >> > >
    >> >> >> > > SELECT CASE WHEN whatever THEN 'foo' ELSE 'bar' END AS whatever;
    >> >> >> >
    >> >> >> > I understand this motivation - although I was more happy with
    >> >> >> > server
    >> >> >> > side solution.
    >> >> >> >
    >> >> >>
    >> >> >> Was a server side implementation submitted before? I can change it,
    >> >> >> but
    >> >> >> I
    >> >> >> did it on the client side like the null display was done.
    >> >> >
    >> >> > Or how about both?
    >> >>
    >> >> Surely one would break the other?
    >> >>
    >> >
    >> > If using both.
    >>
    >> Yes. :)
    >
    > Really server would override client.
    
    Come to think of it, if the client could detect the server's bool out
    config, it could override the server in that instance since it would
    know what it was looking for, so perhaps they could coexist.
    
    -- 
    Thom
    
    
    
  15. Re: PATCH: psql boolean display

    Phil Sorber <phil@omniti.com> — 2012-08-20T22:31:57Z

    On Aug 20, 2012 6:28 PM, "Kevin Grittner" <Kevin.Grittner@wicourts.gov>
    wrote:
    >
    > Gurjeet Singh <singh.gurjeet@gmail.com> wrote:
    >
    > > On occasions I have wanted psql to emit the full 'True'/'False'
    > > words instead of cryptic one-letter t/f, which can get lost on
    > > long rows that get wrapped around on screen. Writing long-winded
    > > CASE expressions to get the effect is too much for small ad-hoc
    > > queries.
    > >
    > > I thought of inventing a data type whose out-function would emit
    > > these strings, and tack a ::mybool to the expression I want
    > > modified. But that would break the applications if somebody pasted
    > > the same  query in an application (JDBC or some such that
    > > understands boolean) and expected a boolean data type instead of a
    > > text output of an expression.
    >
    > The type itself does output true/false; it's just psql that uses
    > t/f.
    >
    > test=# select 'true'::boolean::text;
    >  text
    > ------
    >  true
    > (1 row)
    >
    > test=# select 'false'::boolean::text;
    >  text
    > -------
    >  false
    > (1 row)
    >
    > That has always seemed quite odd (and occasionally inconvenient) to
    > me.
    
    I think that may be from the cast. I didn't see any transformation in psql.
    Looked like it was raw output from the server.
    
    >
    > -Kevin
    
  16. Re: PATCH: psql boolean display

    Phil Sorber <phil@omniti.com> — 2012-08-20T22:57:03Z

    On Aug 20, 2012 6:31 PM, "Thom Brown" <thom@linux.com> wrote:
    >
    > On 20 August 2012 23:16, Phil Sorber <phil@omniti.com> wrote:
    > >
    > > On Aug 20, 2012 6:08 PM, "Thom Brown" <thom@linux.com> wrote:
    > >>
    > >> On 20 August 2012 23:06, Phil Sorber <phil@omniti.com> wrote:
    > >> >
    > >> > On Aug 20, 2012 5:56 PM, "Thom Brown" <thom@linux.com> wrote:
    > >> >>
    > >> >> On 20 August 2012 22:31, Phil Sorber <phil@omniti.com> wrote:
    > >> >> > On Aug 20, 2012 5:19 PM, "Phil Sorber" <phil@omniti.com> wrote:
    > >> >> >>
    > >> >> >> On Aug 20, 2012 5:11 PM, "Pavel Stehule" <pavel.stehule@gmail.com
    >
    > >> >> >> wrote:
    > >> >> >> >
    > >> >> >> > 2012/8/20 Robert Haas <robertmhaas@gmail.com>:
    > >> >> >> > > On Sun, Aug 19, 2012 at 12:02 PM, Phil Sorber <
    phil@omniti.com>
    > >> >> >> > > wrote:
    > >> >> >> > >> I am providing a patch to allow you to change the output of
    a
    > >> >> >> > >> boolean
    > >> >> >> > >> value in psql much like you can do with NULL. A client
    > >> >> >> > >> requested
    > >> >> >> > >> this
    > >> >> >> > >> feature and we thought it may appeal to someone else in the
    > >> >> >> > >> community.
    > >> >> >> > >>
    > >> >> >> > >> The patch includes updated docs and a regression test. The
    code
    > >> >> >> > >> changes themselves are pretty simple and straightforward.
    > >> >> >> > >>
    > >> >> >> > >> Example from the regression test:
    > >> >> >> > >>
    > >> >> >> > >> SELECT true, false;
    > >> >> >> > >>  bool | bool
    > >> >> >> > >> ------+------
    > >> >> >> > >>  t    | f
    > >> >> >> > >> (1 row)
    > >> >> >> > >>
    > >> >> >> > >> \pset booltrue 'foo'
    > >> >> >> > >> \pset boolfalse 'bar'
    > >> >> >> > >> SELECT true, false;
    > >> >> >> > >>  bool | bool
    > >> >> >> > >> ------+------
    > >> >> >> > >>  foo  | bar
    > >> >> >> > >> (1 row)
    > >> >> >> > >>
    > >> >> >> > >> \pset booltrue 't'
    > >> >> >> > >> \pset boolfalse 'f'
    > >> >> >> > >> SELECT true, false;
    > >> >> >> > >>  bool | bool
    > >> >> >> > >> ------+------
    > >> >> >> > >>  t    | f
    > >> >> >> > >> (1 row)
    > >> >> >> > >>
    > >> >> >> > >> As always, comments welcome.
    > >> >> >> > >
    > >> >> >> > > Why not just do it in the SQL?
    > >> >> >> > >
    > >> >> >> > > SELECT CASE WHEN whatever THEN 'foo' ELSE 'bar' END AS
    whatever;
    > >> >> >> >
    > >> >> >> > I understand this motivation - although I was more happy with
    > >> >> >> > server
    > >> >> >> > side solution.
    > >> >> >> >
    > >> >> >>
    > >> >> >> Was a server side implementation submitted before? I can change
    it,
    > >> >> >> but
    > >> >> >> I
    > >> >> >> did it on the client side like the null display was done.
    > >> >> >
    > >> >> > Or how about both?
    > >> >>
    > >> >> Surely one would break the other?
    > >> >>
    > >> >
    > >> > If using both.
    > >>
    > >> Yes. :)
    > >
    > > Really server would override client.
    >
    > Come to think of it, if the client could detect the server's bool out
    > config, it could override the server in that instance since it would
    > know what it was looking for, so perhaps they could coexist.
    
    I think Pavel has a patch in that is meant to sync variables between client
    and server. Perhaps we can use the same facility?
    
    >
    > --
    > Thom
    
  17. Re: PATCH: psql boolean display

    Tatsuo Ishii <ishii@postgresql.org> — 2012-08-20T23:09:35Z

    > On Aug 20, 2012 6:28 PM, "Kevin Grittner" <Kevin.Grittner@wicourts.gov>
    > wrote:
    >>
    >> Gurjeet Singh <singh.gurjeet@gmail.com> wrote:
    >>
    >> > On occasions I have wanted psql to emit the full 'True'/'False'
    >> > words instead of cryptic one-letter t/f, which can get lost on
    >> > long rows that get wrapped around on screen. Writing long-winded
    >> > CASE expressions to get the effect is too much for small ad-hoc
    >> > queries.
    >> >
    >> > I thought of inventing a data type whose out-function would emit
    >> > these strings, and tack a ::mybool to the expression I want
    >> > modified. But that would break the applications if somebody pasted
    >> > the same  query in an application (JDBC or some such that
    >> > understands boolean) and expected a boolean data type instead of a
    >> > text output of an expression.
    >>
    >> The type itself does output true/false; it's just psql that uses
    >> t/f.
    >>
    >> test=# select 'true'::boolean::text;
    >>  text
    >> ------
    >>  true
    >> (1 row)
    >>
    >> test=# select 'false'::boolean::text;
    >>  text
    >> -------
    >>  false
    >> (1 row)
    >>
    >> That has always seemed quite odd (and occasionally inconvenient) to
    >> me.
    > 
    > I think that may be from the cast. I didn't see any transformation in psql.
    > Looked like it was raw output from the server.
    
    Right. "t", "f" are generated in backend. See boolout() in
    backend/utils/adt/bool.c for more details.
    --
    Tatsuo Ishii
    SRA OSS, Inc. Japan
    English: http://www.sraoss.co.jp/index_en.php
    Japanese: http://www.sraoss.co.jp
    
    
    
  18. Re: PATCH: psql boolean display

    Tom Lane <tgl@sss.pgh.pa.us> — 2012-08-20T23:19:03Z

    "Kevin Grittner" <Kevin.Grittner@wicourts.gov> writes:
    > The type itself does output true/false; it's just psql that uses
    > t/f.
    
    No, 't'/'f' is what boolout() returns.  The 'true'/'false' results from
    casting bool to text are intentionally different --- IIRC, Peter E.
    argued successfully that this cast behavior is required by SQL spec.
    But we'd already been returning 't'/'f' to applications for far too many
    years to change it.  (And that argument has not gotten any weaker since
    then.  Keep in mind that Postgres was returning 't'/'f' for bool years
    before the SQL spec even had a boolean type.)
    
    If we're going to do something like this at all, I agree that psql is
    the place to do it, not the server.  But my beef with this patch is that
    it's thinking too small --- why would bool be the only type that
    somebody would want to editorialize on the display of?  I'd rather see
    some general "substitute this for that in display of columns of type X"
    feature.
    
    			regards, tom lane
    
    
    
  19. Re: PATCH: psql boolean display

    Phil Sorber <phil@omniti.com> — 2012-08-21T03:55:52Z

    On Mon, Aug 20, 2012 at 7:19 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
    > "Kevin Grittner" <Kevin.Grittner@wicourts.gov> writes:
    >> The type itself does output true/false; it's just psql that uses
    >> t/f.
    >
    > No, 't'/'f' is what boolout() returns.  The 'true'/'false' results from
    > casting bool to text are intentionally different --- IIRC, Peter E.
    > argued successfully that this cast behavior is required by SQL spec.
    > But we'd already been returning 't'/'f' to applications for far too many
    > years to change it.  (And that argument has not gotten any weaker since
    > then.  Keep in mind that Postgres was returning 't'/'f' for bool years
    > before the SQL spec even had a boolean type.)
    >
    > If we're going to do something like this at all, I agree that psql is
    > the place to do it, not the server.  But my beef with this patch is that
    > it's thinking too small --- why would bool be the only type that
    > somebody would want to editorialize on the display of?  I'd rather see
    > some general "substitute this for that in display of columns of type X"
    > feature.
    >
    >                         regards, tom lane
    
    Sorry, was on my phone before and couldn't type the response I wanted to.
    
    I like where your head is with the more general case, and I tried to
    think along those lines too, but I could not come up with a grand
    unifying way to do even null and boolean together, never mind other
    ways that I hadn't even thought about. The boolean case is a single
    datatype where the null case crosses all nullable types. With null you
    only have to handle one case, with boolean, you have two.
    
    What I settled upon was the simplest way I could think of with the
    most flexibility. In my opinion, the utility of this patch outweigh's
    the niche implementation. I'd welcome other approaches that covered
    this in a more generic way, I just can't think of any that aren't
    overly complex.
    
    
    
  20. Re: PATCH: psql boolean display

    Pavel Stehule <pavel.stehule@gmail.com> — 2012-08-22T08:40:02Z

    2012/8/21 Tom Lane <tgl@sss.pgh.pa.us>:
    > "Kevin Grittner" <Kevin.Grittner@wicourts.gov> writes:
    >> The type itself does output true/false; it's just psql that uses
    >> t/f.
    >
    > No, 't'/'f' is what boolout() returns.  The 'true'/'false' results from
    > casting bool to text are intentionally different --- IIRC, Peter E.
    > argued successfully that this cast behavior is required by SQL spec.
    > But we'd already been returning 't'/'f' to applications for far too many
    > years to change it.  (And that argument has not gotten any weaker since
    > then.  Keep in mind that Postgres was returning 't'/'f' for bool years
    > before the SQL spec even had a boolean type.)
    >
    > If we're going to do something like this at all, I agree that psql is
    > the place to do it, not the server.  But my beef with this patch is that
    > it's thinking too small --- why would bool be the only type that
    > somebody would want to editorialize on the display of?  I'd rather see
    > some general "substitute this for that in display of columns of type X"
    > feature.
    >
    
    can you explain your idea, please? - I can't to imagine any general
    solution for other types than "enum" like types (without significant
    enhancing of psql scripting possibilities)
    
    Regards
    
    Pavel
    
    >                         regards, tom lane