| From: | Richard Huxton <dev(at)archonet(dot)com> |
|---|---|
| To: | Magnus Hagander <mha(at)sollentuna(dot)net> |
| Cc: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: Counting records in a PL/pgsql cursor |
| Date: | 2006-11-03 10:41:21 |
| Message-ID: | 454B1CD1.3060901@archonet.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Magnus Hagander wrote:
> Is there any way to count how many hits I got in a cursor in PL/pgsql?
>
> I have a function that will "window" through the result of a (large)
> query based on two parameters, but I also want to return the number of
> hits to the client. Right now I'm looping through the entire cursor and
> incrementing a local variable, which I later return (along with the
> first <n> records in the resultset) to the client. But this seems
> horribly inefficient... I'd just like to ask "how many rows are in this
> cursor", is there a way to do that without looping through them all?
Not really - that's the point of a cursor, after all. If possible, the
planner should give you the first row before it has all of them, so it
might not even know.
--
Richard Huxton
Archonet Ltd
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Martijn van Oosterhout | 2006-11-03 10:47:34 | Re: Counting records in a PL/pgsql cursor |
| Previous Message | Martijn van Oosterhout | 2006-11-03 10:07:53 | Re: start up and shut down script |