Обсуждение: move forward 0 from foo;
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.
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