From: | Rui DeSousa <rui(at)crazybean(dot)net> |
---|---|
To: | Wells Oliver <wells(dot)oliver(at)gmail(dot)com> |
Cc: | pgsql-admin <pgsql-admin(at)postgresql(dot)org> |
Subject: | Re: percentile_cont from array? |
Date: | 2023-09-12 00:51:38 |
Message-ID: | 333B10FF-ADD4-432C-B3D2-7A48E9E5ADF6@crazybean.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
> On Sep 11, 2023, at 4:01 PM, Wells Oliver <wells(dot)oliver(at)gmail(dot)com> wrote:
>
> 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 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
;
From | Date | Subject | |
---|---|---|---|
Next Message | Laurenz Albe | 2023-09-12 02:24:45 | Re: pg_stat_statements_info |
Previous Message | Tom Lane | 2023-09-12 00:08:14 | Re: btree/gist index on date and searching using BETWEEN or >= and <= |