MML1357
MML1357

Reputation: 157

Get logical result of boolean columns in several rows


If I have a column which store boolean values, how can I apply OR operator over several rows of that column? I hope I don't have to use joins.

Upvotes: 1

Views: 629

Answers (1)

zolamk
zolamk

Reputation: 6427

You can use postgres aggregate functions for this, specifically bool_or and bool_and aggregate functions

create table bools (
  a boolean
);

insert into bools values(true), (true), (false);

select bool_or(a) from bools;

here is a working example https://www.db-fiddle.com/f/fBoZzyXzF4H28tALVupZfC/1

Upvotes: 4

Related Questions