Re: Boolean output format

Jeff Davis <list-pgsql-general@empires.org>

From: Jeff Davis <list-pgsql-general@empires.org>
To: Garo Hussenjian <garo@xapnet.com>, pgsql-general@postgresql.org
Date: 2002-10-05T01:36:35Z
Lists: pgsql-general
The best way change the output style in general is a stored procedure. 
However, with booleans it's simple enough that you could write it out inline 
if you want:
------------------------------------------------------------------------------
jdavis=> create table b(a bool);
CREATE
jdavis=> insert into b values('t');
INSERT 67682 1
jdavis=> insert into b values('f');
INSERT 67683 1
jdavis=> select case when a then 'YES' else 'NO' end from b ;
 case 
------
 YES
 NO
(2 rows)
--------------------------------------------------------------------------------

The case statement basically just special cases the two values. In this case 
it of course changes 't' to 'YES' and 'f' to 'NO'.

You could also make a SQL function out of it no problem:

jdavis=> create function myfn(bool) returns text as 'select case when $1 then 
''YES'' else ''NO'' end;' language 'sql';

Then just use that in your selects:
jdavis=> select myfn(a) from b;
 myfn 
------
 YES
 NO
(2 rows)


Regards,
	Jeff Davis


On Friday 04 October 2002 06:17 pm, Garo Hussenjian wrote:
> A friend of mine has told me that using the Zope pgsql driver you can set
> the output format of postgres booleans...
>
> Unfortunately, I'm using php and would like to do this also.
>
> Is the zope driver doing this or is it some sort of option that can be sent
> when the connection is made or a query that can be run?
>
> Thanks,
> Garo.
>
>
> =-=-==-=-=-==
>
> Xapnet Internet Solutions
> 1501 Powell St., Suite N
> Emeryville, CA 94608
>
> Tel - (510) 655-9771
> Fax - (510) 655-9775
> Web - http://www.xapnet.com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)