How to use Boolean data type

Moderator: NorbertKrupa

Post Reply
Jess.mic
Newbie
Newbie
Posts: 15
Joined: Tue Jun 11, 2013 11:02 pm

How to use Boolean data type

Post by Jess.mic » Thu Apr 17, 2014 2:43 am

Can we use case statement on boolean datatype??

For e.g

case when COALESCE(test.Flag,'T') like 't%' or '%T%' then 1 else 0 end ;

here flag is a column in test table with boolean datatype.
I was trying to this in my etl and I was getting error.

Thanks;

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: How to use Boolean data type

Post by JimKnicely » Thu Apr 17, 2014 3:51 am

Hi,

You don't need the LIKE. Try testing against the column only in the WHERE clause. It's a boolean ;)

Code: Select all

vertica=> create table test(c1 boolean);
CREATE TABLE

vertica=> insert into test values (true);
 OUTPUT 
--------
      1
(1 row)

vertica=> select (case when c1 then 'true' else 'false' end) c1 from test;
  c1  
------
 true
(1 row)
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

Post Reply

Return to “Vertica SQL”