Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 2309 invoked from network); 8 May 2008 08:08:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 May 2008 08:08:16 -0000 Received: (qmail 89867 invoked by uid 500); 8 May 2008 08:08:18 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 89839 invoked by uid 500); 8 May 2008 08:08:18 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 89828 invoked by uid 99); 8 May 2008 08:08:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 May 2008 01:08:18 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.130] (HELO eos.apache.org) (140.211.11.130) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 May 2008 08:07:40 +0000 Received: from eos.apache.org (localhost [127.0.0.1]) by eos.apache.org (Postfix) with ESMTP id 3A88AD2D3 for ; Thu, 8 May 2008 08:07:55 +0000 (GMT) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Apache Wiki To: derby-commits@db.apache.org Date: Thu, 08 May 2008 08:07:55 -0000 Message-ID: <20080508080755.16844.75021@eos.apache.org> Subject: [Db-derby Wiki] Update of "OLAPRowNumber" by JohnHEmbretsen X-Virus-Checked: Checked by ClamAV on apache.org Dear Wiki user, You have subscribed to a wiki page or wiki category on "Db-derby Wiki" for change notification. The following page has been changed by JohnHEmbretsen: http://wiki.apache.org/db-derby/OLAPRowNumber The comment on the change is: Added examples and doc references ------------------------------------------------------------------------------ Thus the ROW_NUMBER function has a very simple syntax. - == Example == + == Examples == A nice example of the ROW_NUMBER function is provided in DERBY-581: @@ -37, +37 @@ In this example the ROW_NUMBER function is used to limit the query as soon as the first N rows have been determined. + Note that the above example is not supported by the current implementation (Derby 10.4.1.3 / May 2008), since this implementation has some [http://db.apache.org/derby/docs/10.4/ref/rreffuncrownumber.html limitations]. + + Examples supported by the current implementation are included below, as well as on the [http://db.apache.org/derby/faq.html#limit Derby FAQ web page] since the ROW_NUMBER function may be used as a replacement for the `LIMIT` and `OFFSET` keywords used in some other databases (and many users ask about this functionality). + + For example, querying a table with 500000 rows, retrieving the first 5 rows only (using the IJ tool): + + {{{ + ij> SELECT * FROM ( + > SELECT ROW_NUMBER() OVER() AS rownum, myLargeTable.* + > FROM myLargeTable + > ) AS tmp + > WHERE rownum <= 5; + + + ROWNUM |A |B + ----------------------------------------------------------------------------------- + 1 |1 |This is row number 1 + 2 |2 |This is row number 2 + 3 |3 |This is row number 3 + 4 |4 |This is row number 4 + 5 |5 |This is row number 5 + + 5 rows selected + }}} + (corresponding to "`SELECT * FROM myLargeTable LIMIT 5`" in some other databases) + + Example retreiving rows 200001 to 200005: + + {{{ + ij> SELECT * FROM ( + > SELECT ROW_NUMBER() OVER() AS rownum, myLargeTable.* + > FROM myLargeTable + > ) AS tmp + > WHERE rownum > 200000 AND rownum <= 200005; + + + ROWNUM |A |B + ----------------------------------------------------------------------------------- + 200001 |200001 |This is row number 200001 + 200002 |200002 |This is row number 200002 + 200003 |200003 |This is row number 200003 + 200004 |200004 |This is row number 200004 + 200005 |200005 |This is row number 200005 + + 5 rows selected + }}} + (corresponding to "`SELECT * FROM myLargeTable LIMIT 5 OFFSET 200000`" in some other databases) + == Current Implementation == - The ROW_NUMBER() window function is currently not implemented, and thereby not supported. + An implementation of the ROW_NUMBER() window function is included in Derby starting with the 10.4.1.3 release. Limitations and usage description may be found in the Derby Reference Manual, [http://db.apache.org/derby/docs/dev/ref/rreffuncrownumber.html ROW_NUMBER built-in function]. + == Proposed Changes ==