Sudip
Sudip

Reputation: 23

How to convert Boolean array to Single Boolean or Single String in Postgres

I have problem converting a boolean array like {true,true} or {}. The result should be true and null, respectively.

What I have currently is {true,}, {true,true} and {}. But I need the result as true, true and null. Please help.

My query is:

select t, array_agg(distinct abc) as abc
from tbl

I want to convert array_agg to a single boolean or string value.

Upvotes: 0

Views: 634

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 247235

Don't use array_agg. Use bool_or instead:

SELECT t, bool_or(abc) AS abc
FROM tbl;

Upvotes: 1

Related Questions