MOVE doesn't return number of rows

From: Phil Endecott <spam_from_postgresql_general(at)chezphil(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: MOVE doesn't return number of rows
Date: 2004-09-09 12:57:28
Message-ID: 41405338.4050407@chezphil.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ben Trewern 2004-09-09 12:59:50 pg_dump/pg_dumpall do not correctly dump search_path
Previous Message Pierre-Frédéric Caillaud 2004-09-09 12:56:35 Byte Sizes