Re: Convert boolean field to a 0 or a 1 in a select statement

From: "Zelaznik, Steve" <szelazni(at)AEGONUSA(dot)com>
To: Sameer Kumar <sameer(dot)kumar(at)ashnik(dot)com>, JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Convert boolean field to a 0 or a 1 in a select statement
Date: 2015-01-13 14:18:41
Message-ID: 77CAECB87E4C6748A77C194E6D8F6B9626146338@crexhtmail04.us.aegon.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I’m more explicit with my CASE statements, explicitly putting the equals sign in place. Such as in the attachment “explicit_equals.gif”. I’m not sure how your CASE statement works, but generally you can only omit the equals sign when you’re dealing with a pure Boolean value, such as the other attachment “pure_ bool.gif”.

-Steve Z

From: pgsql-novice-owner(at)postgresql(dot)org [mailto:pgsql-novice-owner(at)postgresql(dot)org] On Behalf Of Sameer Kumar
Sent: Monday, January 12, 2015 1:31 AM
To: JORGE MALDONADO
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: [NOVICE] Convert boolean field to a 0 or a 1 in a select statement

On Sat, Jan 10, 2015 at 12:47 AM, JORGE MALDONADO <jorgemal1960(at)gmail(dot)com<mailto:jorgemal1960(at)gmail(dot)com>> wrote:
CAST(fce_subdivision as CHAR) AS fce_subdivision_aux,
CASE CAST(fce_subdivision as CHAR)
WHEN 'f' THEN '0'
WHEN 't' THEN '1'
END

​Why do you want to cast it first to char?

And anyways what is the issue with casting it to number first and then casting it to char?

Best Regards,

Sameer Kumar | Database Consultant

ASHNIK PTE. LTD.

101 Cecil Street, #11-11 Tong Eng Building, Singapore 069533

M: +65 8110 0350 T: +65 6438 3504 | www.ashnik.com<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.ashnik.com_&d=AwMFaQ&c=9g4MJkl2VjLjS6R4ei18BA&r=Csoa4Ox_NnLjRJC7azdxiYKatudnOOyyw_27R7cxSUw&m=4qcwFI03sfow3r2enWPSfMyKVidZAjUQ1q9FRj4Lk8g&s=gRzyTbn3Mhf7x0QwZdjQt6FUXuFeVViwFtYnDk5X92A&e=>

[icons]

[Email patch]<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.ashnik.com_&d=AwMFaQ&c=9g4MJkl2VjLjS6R4ei18BA&r=Csoa4Ox_NnLjRJC7azdxiYKatudnOOyyw_27R7cxSUw&m=4qcwFI03sfow3r2enWPSfMyKVidZAjUQ1q9FRj4Lk8g&s=gRzyTbn3Mhf7x0QwZdjQt6FUXuFeVViwFtYnDk5X92A&e=>

This email may contain confidential, privileged or copyright material and is solely for the use of the intended recipient(s).

Attachment Content-Type Size
image/gif 23.5 KB
image/gif 14.9 KB

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Sameer Kumar 2015-01-14 14:02:14 Re: Convert boolean field to a 0 or a 1 in a select statement
Previous Message Sameer Kumar 2015-01-12 06:31:27 Re: Convert boolean field to a 0 or a 1 in a select statement