Обсуждение: convert bool result query
I there!! How can I receive in my query result '1' or '0' instead of 't' and 'f'. tks in advance _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
On Wed, Jan 11, 2006 at 06:41:38PM +0000, Luis Silva wrote:
> I there!! How can I receive in my query result '1' or '0' instead of 't'
> and 'f'. tks in advance
In PostgreSQL 8.1 you can simply cast a boolean value to integer:
test=> SELECT 't'::boolean::integer, 'f'::boolean::integer;
int4 | int4
------+------
1 | 0
(1 row)
In earlier versions you can create such a cast yourself or use a
CASE expression:
test=> SELECT CASE 't'::boolean WHEN true THEN 1 ELSE 0 END;
case
------
1
(1 row)
test=> SELECT CASE 'f'::boolean WHEN true THEN 1 ELSE 0 END;
case
------
0
(1 row)
--
Michael Fuhr
TKS a lot!!! It worked!! >From: Michael Fuhr <mike@fuhr.org> >To: Luis Silva <lfs12@hotmail.com> >CC: pgsql-novice@postgresql.org >Subject: Re: [NOVICE] convert bool result query >Date: Wed, 11 Jan 2006 11:57:09 -0700 > >On Wed, Jan 11, 2006 at 06:41:38PM +0000, Luis Silva wrote: > > I there!! How can I receive in my query result '1' or '0' instead of 't' > > and 'f'. tks in advance > >In PostgreSQL 8.1 you can simply cast a boolean value to integer: > >test=> SELECT 't'::boolean::integer, 'f'::boolean::integer; > int4 | int4 >------+------ > 1 | 0 >(1 row) > >In earlier versions you can create such a cast yourself or use a >CASE expression: > >test=> SELECT CASE 't'::boolean WHEN true THEN 1 ELSE 0 END; > case >------ > 1 >(1 row) > >test=> SELECT CASE 'f'::boolean WHEN true THEN 1 ELSE 0 END; > case >------ > 0 >(1 row) > >-- >Michael Fuhr _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/