Counting records in a PL/pgsql cursor - Mailing list pgsql-general

From Magnus Hagander
Subject Counting records in a PL/pgsql cursor
Date
Msg-id 6BCB9D8A16AC4241919521715F4D8BCEA0FCEB@algol.sollentuna.se
Whole thread Raw
Responses Re: Counting records in a PL/pgsql cursor  (Richard Huxton <dev@archonet.com>)
Re: Counting records in a PL/pgsql cursor  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
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?


//Magnus

pgsql-general by date:

Previous
From: Andreas Kretschmer
Date:
Subject: Re: Is there anyway to...
Next
From: "SunWuKung"
Date:
Subject: Catch multiple records when doing Select Into