2014-05-05 23:13:06 +08:00
|
|
|
--
|
|
|
|
-- Determine the Quantile classifications from a numeric array
|
|
|
|
--
|
|
|
|
-- @param in_array A numeric array of numbers to determine the best
|
|
|
|
-- bins based on the Quantile method.
|
|
|
|
--
|
|
|
|
-- @param breaks The number of bins you want to find.
|
|
|
|
--
|
2017-12-06 05:16:39 +08:00
|
|
|
--
|
2019-05-31 21:29:28 +08:00
|
|
|
CREATE OR REPLACE FUNCTION @extschema@.CDB_QuantileBins(in_array numeric[], breaks int)
|
2017-12-06 05:16:39 +08:00
|
|
|
RETURNS numeric[]
|
|
|
|
AS $$
|
2018-03-08 23:00:52 +08:00
|
|
|
SELECT
|
2018-03-08 23:21:43 +08:00
|
|
|
percentile_disc(Array(SELECT generate_series(1, breaks) / breaks::numeric))
|
2018-03-08 23:00:52 +08:00
|
|
|
WITHIN GROUP (ORDER BY x ASC) AS p
|
|
|
|
FROM
|
|
|
|
unnest(in_array) AS x;
|
2018-03-08 23:14:08 +08:00
|
|
|
$$ language SQL IMMUTABLE STRICT PARALLEL SAFE;
|