Re: [HACKERS] MOVE strangeness

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Jeroen T(dot) Vermeulen" <jtv(at)xs4all(dot)nl>, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] MOVE strangeness
Date: 2002-12-27 14:03:20
Message-ID: 200212271403.gBRE3Ki04490@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > Sorry, I am not understanding. If he does:
> > ...
> > here, isn't he sitting at the start of the fourth row, no?
>
> No. He is sitting *on* the third row. If he now does FETCH 1, he will
> advance to and return the fourth row; on the other hand, if he does
> FETCH -1, he will back up to and return the second row.
>
> The cursor must be considered to be positioned on its current row, not
> between rows, or the SQL-defined operations UPDATE WHERE CURRENT OF and
> DELETE WHERE CURRENT OF don't make any sense. (We don't support those
> yet, but we should someday.)
>
> BTW, looking at Date and the SQL spec, I now realize that the recently
> made change to convert FETCH 0 into a no-op is wrong; per spec, FETCH
> RELATIVE 0 means "re-fetch the current row, if any". By analogy, MOVE 0
> should probably return "MOVE 1" if you are on a real row, "MOVE 0" if
> you are not, corresponding to the number of rows you'd have gotten from
> FETCH 0. Ugly, but ...

OK, patch attached. The patch also makes the cursor offset a long from
the parser into the executor. The tuple counter is already a long in
the executor.

test=> CREATE TABLE test (x int);
insert into testCREATE TABLE
test=> INSERT INTO test VALUES (1);
INSERT 149758 1
test=> BEGIN;
BEGIN
test=> DECLARE xx CURSOR FOR SELECT * FROM test;
DECLARE CURSOR
test=> MOVE 0 FROM xx;
MOVE 0
test=> FETCH 1 FROM xx;
x
---
1
(1 row)

test=> MOVE 0 FROM xx;
MOVE 1
test=> FETCH 0 FROM xx;
x
---
1
(1 row)

test=> FETCH 1 FROM xx;
x
---
(0 rows)

test=> MOVE 0 FROM xx;
MOVE 0

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

Attachment Content-Type Size
unknown_filename text/plain 5.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2002-12-27 14:10:17 Re: please apply patch to CVS ( 7.3 and 7.4dev)
Previous Message Bruce Momjian 2002-12-27 13:37:25 PostgreSQL article

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2002-12-27 14:06:41 Re: max_fsm_pages increased to 1000 by default
Previous Message Kevin Brown 2002-12-27 08:04:36 Re: MOVE strangeness