I expected "MOVE FORWARD 0 FROM foo;" to always return
0, but I have found this not to be the case. Could
anybody comment whether this is expected:
mow=# begin;
BEGIN
mow=# create table a (a integer);
CREATE TABLE
mow=# insert into a values ( 1 );
INSERT 1823482 1
mow=# insert into a values ( 1 );
INSERT 1823485 1
mow=# declare foo cursor for select * from a;
DECLARE CURSOR
mow=# move forward 0 from foo;
MOVE 0
mow=# fetch forward 1 from foo;a
---1
(1 row)
mow=# move forward 0 from foo;
MOVE 1
mow=# move forward 1 from foo;
MOVE 1
mow=# fetch forward 1 from foo;a
---
(0 rows)
mow=# move forward 0 from foo;
MOVE 0
mow=# select version(); version
---------------------------------------------------------------------PostgreSQL 7.4.1 on i386-unknown-openbsd2.8,
compiledby GCC 2.95.3
(1 row)
Basically I found it odd that the MOVE FORWARD 0
in the middle returned 1. Of course I can avoid the
MOVE FORWARD 0 in my application logic, but it meant
special casing the instance for 0.
The docs don't seem to be too verbose on the subject:
http://www.postgresql.org/docs/7.4/interactive/sql-move.html
On successful completion, a MOVE command returns a command tag of the form
MOVE count
The count is the number of rows moved over (possibly zero).
I can see where the difference might originate, but it
seems strange that MOVE FORWARD 0 and MOVE FORWARD 1
could both return "1" so long as the cursor points to something.