opts for array version of percentile_disc
This commit is contained in:
@@ -10,10 +10,9 @@
|
|||||||
CREATE OR REPLACE FUNCTION CDB_QuantileBins(in_array numeric[], breaks int)
|
CREATE OR REPLACE FUNCTION CDB_QuantileBins(in_array numeric[], breaks int)
|
||||||
RETURNS numeric[]
|
RETURNS numeric[]
|
||||||
AS $$
|
AS $$
|
||||||
SELECT array_agg(p) FROM (
|
SELECT
|
||||||
SELECT percentile_disc(idx::numeric / breaks::numeric)
|
percentile_disc(Array(generate_series(1, breaks) / breaks::numeric))
|
||||||
WITHIN GROUP (ORDER BY x ASC) AS p
|
WITHIN GROUP (ORDER BY x ASC) AS p
|
||||||
FROM generate_series(1, breaks) AS idx, unnest(in_array) AS x
|
FROM
|
||||||
GROUP BY idx
|
unnest(in_array) AS x;
|
||||||
) AS quantiles;
|
|
||||||
$$ language sql;
|
$$ language sql;
|
||||||
|
|||||||
Reference in New Issue
Block a user