From: | Jeff Davis <list-pgsql-general(at)empires(dot)org> |
---|---|
To: | Garo Hussenjian <garo(at)xapnet(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Boolean output format |
Date: | 2002-10-05 01:36:35 |
Message-ID: | 200210041836.35713.list-pgsql-general@empires.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
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(at)postgresql(dot)org)
From | Date | Subject | |
---|---|---|---|
Next Message | Garo Hussenjian | 2002-10-05 01:58:32 | Re: Boolean output format |
Previous Message | Garo Hussenjian | 2002-10-05 01:17:23 | Boolean output format |