Skip site navigation (1) Skip section navigation (2)

Re: wip: functions median and percentile

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, Greg Stark <gsstark(at)mit(dot)edu>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, David Fetter <david(at)fetter(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: wip: functions median and percentile
Date: 2010-10-11 14:29:38
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackerspgsql-rrreviewers
On Mon, Oct 11, 2010 at 10:08 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> On Sun, Oct 10, 2010 at 5:16 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> It was pointed out upthread that while median isn't presently
>>> in the standard, Oracle defines it in terms of percentile_cont(0.5)
>>> which *is* in the standard.  What I read in SQL:2008 is that
>>> percentile_cont is defined for all numeric types (returning
>>> approximate numeric with implementation-defined precision),
>>> and for interval (returning interval), and not for any other
>>> input type.  So it appears to me that what we ought to support
>>> is
>>>        median(float8) returns float8
>>>        median(interval) returns interval
>>> and nothing else --- we can rely on implicit casting to convert
>>> any other numeric input type to float8.
>> Isn't there a possibility of a precision loss if numeric gets cast to
>> float8?
> So?  The standard says "implementation-defined precision".  We can
> define it as giving results that are good to float8.  I find it hard to
> imagine an application for median() where that's not good enough;
> and what's more, the difference in comparison speed between float8 and
> numeric would render median() on numeric pretty useless anyway.

I suppose for most applications it won't matter; I just hate losing
precision, and have a deep skepticism of floats, as we've discussed
previously.  :-)

Robert Haas
The Enterprise PostgreSQL Company

In response to

pgsql-hackers by date

Next:From: Tom LaneDate: 2010-10-11 14:31:38
Subject: Re: [JDBC] Support for JDBC setQueryTimeout, et al.
Previous:From: Magnus HaganderDate: 2010-10-11 14:27:50
Subject: Re: [JDBC] Support for JDBC setQueryTimeout, et al.

pgsql-rrreviewers by date

Next:From: Dean RasheedDate: 2010-10-11 15:30:46
Subject: Re: wip: functions median and percentile
Previous:From: Tom LaneDate: 2010-10-11 14:08:53
Subject: Re: wip: functions median and percentile

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group