update 8/26/19
The hangup is that I want to join the result of the function with another table, but I can't seem to get it.
this is the closest I can get, but the result of the function call, is still a record that I can't expand
WITH cviews AS (
select
id
, organization_id
, created_by
, created_at
, modified_by
, modified_at
, name
, description
, cache
from conversation_views
where organization_id = '3b440f43-c5f1-4338-a904-601c4dc8fd15'
)
, aggs AS (
select organization_id, array_agg(id::text) as labels, array_agg(cache) as filters
from cviews
group by organization_id
)
, counts AS (
select
'3b440f43-c5f1-4338-a904-601c4dc8fd15' as organization_id
, zdb.filters(
'conversations_zdx'
, aggs.labels
, aggs.filters
)
from aggs
)
select
cviews.*, counts.*
from cviews
inner join counts on counts.organization_id::UUID = cviews.organization_id::UUID