X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 98FFED1D06C for ; Sat, 10 Apr 2004 19:13:22 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 26081-10 for ; Sat, 10 Apr 2004 19:13:23 -0300 (ADT) Received: from main.gmane.org (main.gmane.org [80.91.224.249]) by svr1.postgresql.org (Postfix) with ESMTP id 1DBB6D1B4BE for ; Sat, 10 Apr 2004 19:13:20 -0300 (ADT) Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1BCQj1-0003gN-00 for ; Sun, 11 Apr 2004 00:13:21 +0200 Received: from 62.79.119.132.adsl.vbr.tiscali.dk ([62.79.119.132]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 11 Apr 2004 00:13:19 +0200 Received: from troels by 62.79.119.132.adsl.vbr.tiscali.dk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 11 Apr 2004 00:13:19 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Troels Arvin Subject: Re: SQL challenge--top 10 for each key value? Date: Sun, 11 Apr 2004 00:13:17 +0200 Lines: 32 Message-ID: References: <33af4fa4e4ec230574cefcff737ea40a@news.teranews.com> <87r7uyf3ki.fsf@stark.xeocode.com> <1081481466.56361.808.camel@jester> <21760.1081491104@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 62.79.119.132.adsl.vbr.tiscali.dk User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/97 X-Sequence-Number: 17472 On Fri, 09 Apr 2004 02:11:44 -0400, Tom Lane wrote: >> ROW_NUMBER() is a spec defined function. (6.10 of SQL200N) > > If the spec doesn't even have a year number yet, you can hardly expect > real implementations to support it ;-) SQL:2003 is finished. Among its new (non-core) OLAP features are a set of "windows functions" (spec section 6.10), which include feature ID T611 (elementary OLAP): - ROW_NUMBER() OVER (...) - RANK() OVER (...) - DENSE_RANK() OVER (...) feature ID T612 (extended OLAP): - PERCENT_RANK() OVER (...) - CUME_DIST() OVER (...) See http://www.acm.org/sigmod/record/issues/0403/index.html#standards for an article which summarizes the news in SQL:2003. ROW_NUMBER() OVER may be used in queries where a PostgreSQL user which use LIMIT. RANK() OVER may be used in queries where a PostgreSQL user would have to come up with a somewhat strange query in order to get acceptable performance, see http://troels.arvin.dk/db/rdbms/#select-top-n-postgresql -- Greetings from Troels Arvin, Copenhagen, Denmark