pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter_e@gmx.net>
To: Mitch Vincent <mitch@venux.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] count() question
Date: Sat, 18 Dec 1999 17:13:41 +0100 (CET)
Message-ID: <Pine.LNX.4.21.9912181655230.356-100000@localhost.localdomain> (raw)
In-Reply-To: <021101bf490b$d43b7ec0$0300000a@doot.org>

On 1999-12-17, Mitch Vincent mentioned:

> So my question is, is there anyway you can get the total number of results
> (using count() or something) and still use the limit directive in the same
> query? I tried looking at the number of result rows too but 10 (the limit)
> is all I come up with.
> 
> I would really like to avoid doing 2 full queries here, if anyone has any
> suggestions please let me know.

Why do you want to avoid that? If you need two different results then you
probably have to use two different queries. I assume you need the count to
display something like "x matches found" and use LIMIT/OFFSET to step
through them page by page. In that case there is really no way but to
query twice. If your query is really complicated and slow you might want
to put the complete query results in a temporary table, and select the
count and the to-be-displayed data from there.


-- 
Peter Eisentraut                  Sernanders väg 10:115
peter_e@gmx.net                   75262 Uppsala
http://yi.org/peter-e/            Sweden





view thread (9+ messages)  latest in thread

Message-ID: <Pine.LNX.4.21.9912181655230.356-100000@localhost.localdomain>
Permalink:  ../Pine.LNX.4.21.9912181655230.356-100000@localhost.localdomain/
Also on:    postgresql.org/message-id/Pine.LNX.4.21.9912181655230.356-100000@localhost.localdomain

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: peter_e@gmx.net, mitch@venux.net
  Subject: Re: [SQL] count() question
  In-Reply-To: <Pine.LNX.4.21.9912181655230.356-100000@localhost.localdomain>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox