I have a function that returns an an array of timestamps. I want to convert these timestamps to dates in yyyy-mm-dd format. I want to flatten the array column that is returned but I am getting:
SQL compilation error: Unknown function FLATTEN
when I run:
with cte as (SELECT
array_construct('2021-09-10'::date,'2021-09-11'::date,'2021-09-12'::date) AS array
,'2021-09-11'::date AS max_date
,date_filter
(
'2021-09-12'::date,
array_construct('2021-09-10'::date,'2021-09-11'::date,'2021-09-12'::date)
) as dates )
select flatten(cte.dates) from cte
Function is:
CREATE OR REPLACE FUNCTION date_filter (max_date DATE, date_list ARRAY)
RETURNS ARRAY
LANGUAGE JAVASCRIPT
AS $$
var dates = DATE_LIST;
return dates.filter(date => date < MAX_DATE);
$$
;