tags:

views:

40

answers:

1

Hi, I would like to ask you how in PostgreSQL can you check if one of boolean values in table's column is true using select or aggregate function?

Thanks.

+1  A: 

You can't use SUM(DATA) but you could cast the value (see below) to int (0=false, 1=true). However it may be more efficient to use EXISTS(...), specially if you are not interested in the number of TRUE values.

create table test(data boolean);
insert into test values(true), (false);
select sum(cast(data as int)) from test;
select exists(select * from test where data);
Thomas Mueller
Be precisely: select exists(select * from test where data='true');It works! Thanks for your reply.
gohohgle