Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Interfaces Jdbc > Re: Query size?
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 5 Topic 1979 of 2010
Post > Topic >>

Re: Query size?

by tgl@[EMAIL PROTECTED] (Tom Lane) Jun 22, 2008 at 02:56 PM

Paul Tomblin <ptomblin@[EMAIL PROTECTED]
> writes:
> What I'm asking though is if there is some way to know before I start 
> returning results, short of doing a "COUNT(*)" first.

No.  Postgres generates query results on the fly, so the server doesn't
know the number of rows that will be returned either, until the query
completes.

You can get an estimate by running EXPLAIN, but those estimates are
frequently far off the mark.

If you're really intent on having an accurate count before you fetch
the results, you can set up the query as a scrollable cursor, do MOVE
FORWARD ALL and note the move count, then MOVE BACKWARD ALL and start
fetching.  This amounts to forcing the server to materialize the whole
result set before you start to fetch it, which is exceedingly expensive,
especially if the result set is very large.

Usually the best bet is to just limit how much you will fetch, using
LIMIT or a cursor as suggested by imad.

			regards, tom lane

-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
 




 5 Posts in Topic:
Query size?
ptomblin@[EMAIL PROTECTED  2008-06-22 07:38:49 
Re: Query size?
immaad@[EMAIL PROTECTED]   2008-06-22 22:23:36 
Re: Query size?
ptomblin@[EMAIL PROTECTED  2008-06-22 08:37:29 
Re: Query size?
tgl@[EMAIL PROTECTED] (T  2008-06-22 14:56:18 
Re: Query size?
immaad@[EMAIL PROTECTED]   2008-06-22 22:55:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 20 8:12:10 CDT 2008.