pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
move forward 0 from foo;
2+ messages / 2 participants
[nested] [flat]

* move forward 0 from foo;
@ 2004-03-23 21:13 Chester Kustarz <chester@arbor.net>
  2004-03-23 22:37 ` Re: move forward 0 from foo; Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Chester Kustarz @ 2004-03-23 21:13 UTC (permalink / raw)
  To: 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.







^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: move forward 0 from foo;
  2004-03-23 21:13 move forward 0 from foo; Chester Kustarz <chester@arbor.net>
@ 2004-03-23 22:37 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2004-03-23 22:37 UTC (permalink / raw)
  To: Chester Kustarz <chester@arbor.net>; +Cc: pgsql-sql

Chester Kustarz <chester@arbor.net> writes:
> I expected "MOVE FORWARD 0 FROM foo;" to always return
> 0, but I have found this not to be the case.

You are misinterpreting the output.  The result is the number of rows
that would have been returned by a FETCH with the same parameters.
FETCH 0 means "re-fetch current row" (don't blame us, this is per SQL
spec), and so it will return 1 row unless you are currently positioned
off the end of the result.  Hence, MOVE 0 returns either 0 or 1
depending on whether you are currently on a row.

It looks like the MOVE documentation is a bit poorly worded; I'll do
something about that.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2004-03-23 22:37 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-03-23 21:13 move forward 0 from foo; Chester Kustarz <chester@arbor.net>
2004-03-23 22:37 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox