1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-07 00:36:50 +03:00

Repair corner-case bug in array version of percentile_cont().

The code for advancing through the input rows overlooked the case that we
might already be past the first row of the row pair now being considered,
in case the previous percentile also fell between the same two input rows.

Report and patch by Andrew Gierth; logic rewritten a bit for clarity by me.
This commit is contained in:
Tom Lane
2014-12-13 11:49:16 -05:00
parent 50f2c0687f
commit b0f479113a
3 changed files with 26 additions and 18 deletions

View File

@ -1423,11 +1423,11 @@ from tenk1;
{{NULL,999,499},{749,249,NULL}}
(1 row)
select percentile_cont(array[0,1,0.25,0.75,0.5,1]) within group (order by x)
select percentile_cont(array[0,1,0.25,0.75,0.5,1,0.3,0.32,0.35,0.38,0.4]) within group (order by x)
from generate_series(1,6) x;
percentile_cont
-----------------------
{1,6,2.25,4.75,3.5,6}
percentile_cont
------------------------------------------
{1,6,2.25,4.75,3.5,6,2.5,2.6,2.75,2.9,3}
(1 row)
select ten, mode() within group (order by string4) from tenk1 group by ten;

View File

@ -533,7 +533,7 @@ select percentile_cont(array[0,0.25,0.5,0.75,1]) within group (order by thousand
from tenk1;
select percentile_disc(array[[null,1,0.5],[0.75,0.25,null]]) within group (order by thousand)
from tenk1;
select percentile_cont(array[0,1,0.25,0.75,0.5,1]) within group (order by x)
select percentile_cont(array[0,1,0.25,0.75,0.5,1,0.3,0.32,0.35,0.38,0.4]) within group (order by x)
from generate_series(1,6) x;
select ten, mode() within group (order by string4) from tenk1 group by ten;