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

Re: Boolean to integer conversion

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Boolean to integer conversion
Date: 2012-03-28 17:36:55
Message-ID: jkvi7i$a82$ (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
JORGE MALDONADO wrote on 28.03.2012 19:20:
> Is it possible to convert a boolean field to integer? (True = 1,
> False = 0)
> In the following example, "price" is a non-zero numeric field and
> "status" is a boolean field. So that, when "status=False" then
> "final_price=0.00" and when "status=True" then "final_price <>
> 0.00".
> SELECT (price * status) AS final_price
> I know that I can use a "CASE WHEN..." statement but, in this case,
> it is not the solution I am looking for.

SELECT (price * status::int) AS final_price

In response to

pgsql-novice by date

Next:From: MephystoDate: 2012-03-28 20:50:53
Subject: Re: Show stored function code
Previous:From: JORGE MALDONADODate: 2012-03-28 17:20:07
Subject: Boolean to integer conversion

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