Обсуждение: MOVE doesn't return number of rows

Поиск
Список
Период
Сортировка

MOVE doesn't return number of rows

От
Phil Endecott
Дата:
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.


Re: MOVE doesn't return number of rows

От
Tom Lane
Дата:
Phil Endecott <spam_from_postgresql_general@chezphil.org> writes:
> According to the documentation for MOVE, it returns the number of rows
> that it has moved over.

That's a documentation bug.  CVS tip has the correct explanation:

    The count is the number of rows that a FETCH command with the same
    parameters would have returned (possibly zero).

> 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?

MOVE FORWARD ALL.

            regards, tom lane