Re: BUG #17428: last_value incorrect for uninitialized sequence

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Glen Edmonds <glen(dot)edmonds(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17428: last_value incorrect for uninitialized sequence
Date: 2022-03-07 15:40:33
Message-ID: CAKFQuwZrRHHxf8UzP+QCE+TSAeuVTytQ8W5oOJrvtLvpdtZt7w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Mar 7, 2022 at 8:23 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Glen Edmonds <glen(dot)edmonds(at)gmail(dot)com> writes:
> > The problem really is that the two states of not initialized and post
> first
> > usage are indistinguishable (both return 1), but the sequence next value
> is
> > different.
>
> They're not indistinguishable: if you look at the is_called flag
> you'll see that it changes.
>
> Correct, the boolean is a superior solution to defining null to mean
something. A bit more verbose but equally functional and easier to read.

> > ie it’s a reasonable expectation that the next value is
> > last_value + 1. IMHO violating this makes it a bug.

> You can call it that if you like, but it's operating as designed
> and documented. I fear it's about twenty years too late to propose
> a redesign.
>
>
And next_value isn't last_value + 1 in any case since we have a block
caching feature. One cannot predict (i.e., without consuming) the
next_value from current state.

David J.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Andrey Borodin 2022-03-08 15:44:31 Re: BUG #17401: REINDEX TABLE CONCURRENTLY creates a race condition on a streaming replica
Previous Message Tom Lane 2022-03-07 15:23:42 Re: BUG #17428: last_value incorrect for uninitialized sequence