Skip site navigation (1) Skip section navigation (2)

Re: convert bool result query

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Luis Silva <lfs12(at)hotmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: convert bool result query
Date: 2006-01-11 18:57:09
Message-ID: 20060111185709.GA87093@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-novice
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

In response to

Responses

pgsql-novice by date

Next:From: Luis SilvaDate: 2006-01-11 19:00:18
Subject: Re: convert bool result query
Previous:From: Luis SilvaDate: 2006-01-11 18:41:38
Subject: convert bool result query

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group