Reputation: 162
When I try to use a UDF that has an aggregate function, I get the following error:
Aggregate function APPROX_QUANTILES not allowed in templated SQL function call
Here's an example function:
CREATE OR REPLACE FUNCTION my_function(x ANY TYPE) AS (
APPROX_QUANTILES(x, 100)[OFFSET(25)]
);
Is there any way to include an aggregate function (in my case, APPROX_QUANTILES
), within a UDF in BigQuery?
Upvotes: 0
Views: 457
Reputation: 172974
Try below instead
CREATE OR REPLACE FUNCTION my_function(x ANY TYPE) AS ((
SELECT APPROX_QUANTILES(y, 100)[OFFSET(25)]
FROM UNNEST(x) y
));
Upvotes: 2