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 replace function percentile_array(numeric, numeric[]) returns real language 'sql' immutable as $$ select percentile_cont($1) within group (order by i asc) from unnest($2) i; $$; select percentile_cont(.9) within group (order by i asc) from unnest(array[1,2,3,4,5]) i ; |