Re: BUG #16018: pg_sequence_last_value() doesn't give results for owners

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Treat <rob(at)xzilla(dot)net>
Cc: PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16018: pg_sequence_last_value() doesn't give results for owners
Date: 2019-09-23 23:40:09
Message-ID: 9246.1569282009@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Robert Treat <rob(at)xzilla(dot)net> writes:
> On Mon, Sep 23, 2019 at 6:34 PM David G. Johnston
> <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>> From pg_sequences:
>> last_value bigint The last sequence value written to disk. If caching is used, this value can be greater than the last value handed out from the sequence. Null if the sequence has not been read from yet. Also, if the current user does not have USAGE or SELECT privilege on the sequence, the value is null.

> Ugh... the situation is further complicated in that setval seems to
> cause a read, but alter sequence restart does not. Fun.

setval can set is_called to either true or false. In the false
state, you get a null here.

>> The "last_value" on the sequence object has a different definition than the one on the relatively new pg_sequences catalog.

> Any chance you have a pointer to documentation on the differences?

David quoted the docs about pg_sequences.last_value.
pg_sequence_last_value() isn't documented separately because you're
not really supposed to call it directly, only through the view.

currval()/lastval() give the last sequence value actually returned in
the current session, independently of what other sessions did since.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Ashesh Vashi 2019-09-24 05:11:39 Re: Query tool won't load
Previous Message Robert Treat 2019-09-23 23:34:03 Re: BUG #16018: pg_sequence_last_value() doesn't give results for owners