I find myself needing to get percentile_cont values from array types and thus did this, wondering if anyone has any "you idiot that's available out of the box here" kind of feedback?
I think it is a personal preference; does the function make the code more readable? The CTE is not needed, nor is the function.
create or replacefunctionpercentile_array(numeric, numeric[])
returnsreal
language'sql'
immutable
as $$
selectpercentile_cont($1) withingroup (order by i asc) from unnest($2) i;
$$;
selectpercentile_cont(.9) withingroup (order by i asc)