Having problems when using array_agg
when a row contains an empty array ({}
).
This is my SQL query:
SELECT service_name, metric_name, array_agg(value_textarray)
FROM service_data
WHERE service_name = 'ActivityDataService'
GROUP BY service_name, metric_name
Where the column definitions are the following:
service_name - text
metric_name - text
value_textarray - text[]
When I execute the query and I have empty array ({}
) in the database, I get the following error:
ERROR: cannot accumulate empty arrays
How should I go about fixing this?
AND value_textarray <> '{}'
took the cake. Thanks.and coalesce(cardinality(value_textarray),0) = 0