Re: SELECT TOP %d PERCENT, or SELECT ... LIMIT %d PERCENT ?

From: "Hitoshi Harada" <umi(dot)tanuki(at)gmail(dot)com>
To: "Grzegorz Jaskiewicz" <gj(at)pointblue(dot)com(dot)pl>
Cc: "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Pg Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: SELECT TOP %d PERCENT, or SELECT ... LIMIT %d PERCENT ?
Date: 2008-10-13 05:06:51
Message-ID: e08cc0400810122206s2e3241feu25d2cb65795c0cf7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2008/10/13 Grzegorz Jaskiewicz <gj(at)pointblue(dot)com(dot)pl>:
>
> On 2008-10-12, at 16:22, Hitoshi Harada wrote:
>
>> 2008/10/12 Robert Haas <robertmhaas(at)gmail(dot)com>:
>>>
>>> I wonder if this could be implemented using the window-function
>>> infrastructure...
>>>
>>
>> Yeah, actually window functions I am working now has percent_rank() or
>> something he wants. That is better than WITH clauses but still we must
>> see the last row before determine the percent. Better than count(*) of
>> course, but I'm not sure it meets his needs.
>>
> excuse my ignorance, apparently I don't recall that patches discussion in
> here. If it pops out, and gets into cvs, can someone remind me of that -
> please ?

You can track pgsql news on David Fetter's blog:
http://people.planetpostgresql.org/dfetter/

> Also, will that patch also be able to speed up count(*) , or is it for
> different purpose ? Sorry if I am repeating the subject, if so - please just
> respond in private.

I guess cume_dist() will do for you:

SELECT id, cume_dist
FROM(
SELECT id, cume_dist() OVER (ORDER BY id)
FROM foo
)s
WHERE cume_dist < 0.3

will produce a result with id of 30% ascending order. I am working on
this window functions infrastructure to get into 8.4 but we're still
not sure if it will.

You can google "window functions" or my design docs on
http://umitanuki.net/pgsql/wfv06/design.html to see what it is for.

Regards,

--
Hitoshi Harada

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Zdenek Kotala 2008-10-13 07:04:37 Re: [PATCH] Extending pg_class info + more flexible TOAST chunk size
Previous Message Joshua D. Drake 2008-10-13 03:15:20 Re: A small note about the difficulty of managing subprojects