Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 213B59F9724 for ; Mon, 5 Nov 2007 10:38:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 03978-02 for ; Mon, 5 Nov 2007 10:38:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from ns1.officenet.no (vpn.officenet.no [193.212.174.13]) by postgresql.org (Postfix) with ESMTP id 03BD79F97FC for ; Mon, 5 Nov 2007 10:38:51 -0400 (AST) Received: from [193.212.174.32] by ns1.officenet.no with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1Ip36A-0003XR-9u; Mon, 05 Nov 2007 15:38:48 +0100 From: Andreas Joseph Krogh Organization: OfficeNet AS To: pgsql-sql@postgresql.org Subject: Re: Returning the total number of rows as a separate column when using limit Date: Mon, 5 Nov 2007 15:38:34 +0100 User-Agent: KMail/1.9.6 (enterprise 0.20070907.709405) Cc: Tom Lane References: <200711050836.38130.andreak@officenet.no> <18728.1194272302@sss.pgh.pa.us> In-Reply-To: <18728.1194272302@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200711051538.34536.andreak@officenet.no> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/13 X-Sequence-Number: 29541 On Monday 05 November 2007 15:18:22 Tom Lane wrote: > Andreas Joseph Krogh writes: > > AFAICS the information about the *total* number of rows is in the > > "result" somehow. When I execute a "limit 1" query with EXPLAIN ANALYZE, > > I se the total number of columns in "rows=3D200819", so the information= is > > there. > > That's only an estimate. Since the query doesn't get executed to > completion thanks to the LIMIT, Postgres really has no idea whether > the estimate is accurate. Ok. The query is ORDER-ed, but you're saying that it doesn't matter and PG= =20 still doesn't have to know the total numbers even if it has to sort the=20 result? Is there a way to perform the LIMIT-query only once and still be able to=20 extract the total number of rows from some "magic function", like=20 Oracle's "over()" analytic function? I will accept a simple "no" if that is= =20 the case, but if it is possible (like it is in Oracle) I would appreciate t= o=20 know how to do it. =2D-=20 Andreas Joseph Krogh Senior Software Developer / Manager =2D-----------------------+---------------------------------------------+ OfficeNet AS | The most difficult thing in the world is to | Karenslyst All=C3=A9 11 | know how to do a thing and to watch | PO. Box 529 Sk=C3=B8yen | somebody else doing it wrong, without | 0214 Oslo | comment. | NORWAY | | Tlf: +47 24 15 38 90 | | =46ax: +47 24 15 38 91 | | Mobile: +47 909 56 963 | | =2D-----------------------+---------------------------------------------+