You cannot count the number of rows in a cursor, unfortunately. I recently ran in to this problem.
As far as I am aware, the only way to count them is to either iterate through them,
or if you are only expecting one or two, perform multiple FETCHES and test if the
record set returned is empty.
http://archives.postgresql.org/pgsql-sql/2005-08/msg00208.php
OPEN cur_overlap FOR EXECUTE 'SELECT *, ....';
FETCH cur_overlap INTO row_one;
FETCH cur_overlap INTO row_two;
IF (row_two.id IS NULL) THEN ....
King regards,
Neil.
This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private
information. If you have received it in error, please notify the sender immediately and delete the original. Any other
useof the email by you is prohibited.