Re: Returning the total number of rows as a separate column when using limit - Mailing list pgsql-sql

From Andreas Joseph Krogh
Subject Re: Returning the total number of rows as a separate column when using limit
Date
Msg-id 200711051538.34536.andreak@officenet.no
Whole thread Raw
In response to Re: Returning the total number of rows as a separate column when using limit  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Returning the total number of rows as a separate column when using limit  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
On Monday 05 November 2007 15:18:22 Tom Lane wrote:
> Andreas Joseph Krogh <andreak@officenet.no> 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=200819", 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
still doesn't have to know the total numbers even if it has to sort the
result?

Is there a way to perform the LIMIT-query only once and still be able to
extract the total number of rows from some "magic function", like
Oracle's "over()" analytic function? I will accept a simple "no" if that is
the case, but if it is possible (like it is in Oracle) I would appreciate to
know how to do it.

--
Andreas Joseph Krogh <andreak@officenet.no>
Senior Software Developer / Manager
------------------------+---------------------------------------------+
OfficeNet AS            | The most difficult thing in the world is to |
Karenslyst Allé 11      | know how to do a thing and to watch         |
PO. Box 529 Skøyen      | somebody else doing it wrong, without       |
0214 Oslo               | comment.                                    |
NORWAY                  |                                             |
Tlf:    +47 24 15 38 90 |                                             |
Fax:    +47 24 15 38 91 |                                             |
Mobile: +47 909  56 963 |                                             |
------------------------+---------------------------------------------+


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Returning the total number of rows as a separate column when using limit
Next
From: Tom Lane
Date:
Subject: Re: Returning the total number of rows as a separate column when using limit