Skip site navigation (1) Skip section navigation (2)

move forward 0 from foo;

From: Chester Kustarz <chester(at)arbor(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: move forward 0 from foo;
Date: 2004-03-23 21:13:39
Message-ID: Pine.BSO.4.44.0403231601530.18218-100000@detroit.arbor.net (view raw or flat)
Thread:
Lists: pgsql-sql
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, compiled by 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.





Responses

pgsql-sql by date

Next:From: Tom LaneDate: 2004-03-23 22:37:10
Subject: Re: move forward 0 from foo;
Previous:From: Bruno Wolff IIIDate: 2004-03-23 20:46:30
Subject: Re: SQL Query

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group