Boolean to integer conversion

From: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Boolean to integer conversion
Date: 2012-03-28 17:20:07
Message-ID: CAAY=A78ijwreBTqwxOWwd8pW-8SzoCaUm4Ah1eRXOewp6MiZwA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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.

Regards,
Jorge Maldonado

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Thomas Kellerer 2012-03-28 17:36:55 Re: Boolean to integer conversion
Previous Message Merlin Moncure 2012-03-28 16:35:01 Re: Show stored function code