Counting records in a PL/pgsql cursor

From: "Magnus Hagander" <mha(at)sollentuna(dot)net>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Counting records in a PL/pgsql cursor
Date: 2006-11-02 21:43:58
Message-ID: 6BCB9D8A16AC4241919521715F4D8BCEA0FCEB@algol.sollentuna.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message rloefgren 2006-11-02 22:54:54 dividing integers not producing decimal fractions
Previous Message Andreas Kretschmer 2006-11-02 20:49:04 Re: Is there anyway to...