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

Re: MOVE strangeness

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jeroen T(dot) Vermeulen" <jtv(at)xs4all(dot)nl>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: MOVE strangeness
Date: 2002-12-26 18:26:11
Message-ID: 2131.1040927171@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
"Jeroen T. Vermeulen" <jtv(at)xs4all(dot)nl> writes:
> Here's something that's been bothering me for a while...  Perhaps this
> is correct behaviour, but I can't quite see how.

It looks fine to me, given the underlying model of how a cursor works,
which probably isn't really written down anywhere :-(.  Briefly:

1. A cursor can be positioned before the first row, after the last row,
or on any individual row of its SELECT result.  The initial state is
before the first row.

2. "FETCH 1" advances the cursor one row (if possible), and if it's not
now after the last row, returns the row the cursor is now on.  "FETCH n"
repeats this operation n times.

3. "FETCH BACKWARD 1" (or FETCH -1) moves the cursor back one row (if
possible), and if it's not now before the first row, returns the row the
cursor is now on.  "FETCH -n" repeats this operation n times.

4. The result count is the number of rows successfully returned (or for
MOVE, the number that would have been returned by the equivalent FETCH).


> This makes it a bit hard for me to figure out just how far I moved my
> cursor backwards!  Moving by BACKWARD ALL will give me the same result
> as moving by -3.

If the return count is not the same as abs(n), then you ran off the end
of the result, and are now positioned before the start or after the end
depending on the requested direction.  If the return count is the same
as abs(n), then you are positioned on a real row.  This doesn't seem any
more confusing to me than any other convention that might have been
picked.

> This does not happen
> if I replace the FETCHes by MOVEs.

I'm a little confused by that remark; it seems to me that FETCH and MOVE
have identical behaviors so far as repositioning the cursor is concerned.
(Internally, MOVE *is* a FETCH, it just suppresses output of the rows.)
Can you give an example where you get different behavior?

			regards, tom lane

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2002-12-26 18:31:50
Subject: Re: Problem with move not returning number of rows affected [was: error when using move, any suggestions?]
Previous:From: Olivier PRENANTDate: 2002-12-26 17:25:18
Subject: Problems with 7.3.1

pgsql-patches by date

Next:From: Bruce MomjianDate: 2002-12-26 18:41:52
Subject: Re: MOVE strangeness
Previous:From: Jeroen T. VermeulenDate: 2002-12-26 01:44:30
Subject: MOVE strangeness

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