pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Bryn Llewellyn <bryn@yugabyte.com>
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: Why does "fetch last from cur" always cause error 55000 for non-scrollable cursor?
Date: Thu, 13 Apr 2023 16:35:46 -0400
Message-ID: <1380649.1681418146@sss.pgh.pa.us> (raw)
In-Reply-To: <3DDA11AC-718C-4B1A-BC98-7FC25DED0259@yugabyte.com>
References: <3DDA11AC-718C-4B1A-BC98-7FC25DED0259@yugabyte.com>

Bryn Llewellyn <bryn@yugabyte.com> writes:
> But why does "fetch last" fail here:

> -- Test Two
> start transaction;
>   declare cur no scroll cursor without hold for
>   select g.val as k, g.val*100 as v
>   from generate_series(1, 10) as g(val)
>   order by g.val;

>   fetch first from cur;
>   fetch last  from cur;
> rollback;

FETCH LAST is implemented as "run forward to the end, then back up one".
You could imagine adding more infrastructure to allow doing it without
backup, but it'd be complicated (not least because the cursor's ending
position would be subtly wrong).

> Finally, I tried the same tests in PG 11.19. There, in Test One, the second "fetch first" succeeds (and gets the right result). But it has to scroll backwards to do this. I'm guessing that the Version 11 behavior was regarded as a bug—and was fixed. When did the behavior change here?

Probably here:

https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=c1b7a6c27

			regards, tom lane





view thread (3+ messages)  latest in thread

Message-ID: <1380649.1681418146@sss.pgh.pa.us>
Permalink:  ../1380649.1681418146@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1380649.1681418146@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, bryn@yugabyte.com
  Subject: Re: Why does "fetch last from cur" always cause error 55000 for non-scrollable cursor?
  In-Reply-To: <1380649.1681418146@sss.pgh.pa.us>
  References: <3DDA11AC-718C-4B1A-BC98-7FC25DED0259@yugabyte.com> <1380649.1681418146@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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