2022-01-21

How to remove NULL from array in Athena

I have arrays aggregated with this query:

select field_name1, 
       field_name2, 
       "array_agg"(DISTINCT <field_name3>) "array_agg"
from <table_name>
group by <field_name1>

Problem is that some outputs have NULL values in them.

['element1', 'element2', NULL]

How can we remove the NULL from array when aggregate values.

I have tried

select field_name1, 
       field_name2, 
       "array_remove"("array_agg"(DISTINCT <field_name1>), NULL) "array_agg_drop_NULL""array_agg"
from <table_name>
group by <field_name1>

but it returns output with all blanks.



from Recent Questions - Stack Overflow https://ift.tt/3ArmbGk
https://ift.tt/eA8V8J

No comments:

Post a Comment