Dear Postgresql experts,
According to the documentation for MOVE, it returns the number of rows
that it has moved over. It seems to me that this is true for MOVE
FORWARD n, but not for MOVE RELATIVE n or MOVE ABSOLUTE n when it always
returns 1:
db=> declare c scroll cursor for select * from p;
DECLARE CURSOR
db=> move absolute -1 in c;
MOVE 1
db=> move absolute 1 in c;
MOVE 1
db=> move absolute 10 in c;
MOVE 1
db=> move relative 10 in c;
MOVE 1
db=> move relative 100 in c;
MOVE 1
db=> move forward 100 in c;
MOVE 100
Is this a bug?
What I'm actually trying to do is to find the number of rows in the
query result. I was hoping to be able to do a "MOVE ABSOLUTE -1" to get
this. Any other suggestions?
Taking a step further back, here's the real problem: I want to present
the user with an index page to chunks of a table, e.g.
Aardvark - Frog
Frozen - Rabbit
Rabies - Zoo
So I need to get something like rows 1, n/3-1, n/3, 2n/3-1, 2n/3, n.
Efficiency is of concern. Is there some way of asking "WHERE row_number
MOD x < 2"? Currently I am running a count(*) version of the query to
get the number of rows and then running it again with a cursor and
fetching the necessary rows. Any other ideas?
This is with 7.4.2.
Regards,
--Phil.