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

From: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Convert boolean field to a 0 or a 1 in a select statement
Date: 2015-01-09 16:47:11
Message-ID: CAAY=A79jns7-tjoZLFFuVhKAPasngRqw29jm2X1CWcRtgRWSWg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I have a SELECT statement which contains a boolean field. The result of
this query must display '0' for false or '1' for true. I will be generating
a text file with this information and a zero or a one is required. I have
tried using the CASE statement without success.

CAST(fce_subdivision as CHAR) AS fce_subdivision_aux,
CASE CAST(fce_subdivision as CHAR)
WHEN 'f' THEN '0'
WHEN 't' THEN '1'
END

I will very much appreciate your feedback.

Respectfully,
Jorge Maldonado

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Steve Crawford 2015-01-09 16:54:27 Re: Convert boolean field to a 0 or a 1 in a select statement
Previous Message Josep Sanchez 2015-01-09 11:11:50 Re: Upgrade Ubuntu - PostgresSQL is ok?