I encountered a very curious behavior in BigQuery.
The following query produces the unexpected result empty array [], since I'm concatenating arrays I'm expecting an array with all the elements that I'm concatenating.
SELECT ARRAY_CONCAT(
(
SELECT ARRAY_AGG(col1) -- This is creating an empty array since condition is always false
FROM ...
WHERE 1 = 2
),
['test']
)
While a very similar query produces the expected result ['test']:
SELECT ARRAY_CONCAT(
[],
['test']
)
And ARRAY_AGG() produces indeed an empty array []:
SELECT ARRAY_AGG(col1) -- This is creating an empty array since condition is always false
FROM ...
WHERE 1 = 2
Why the first query produces an empty array while it is a combination of the second and third query?