Re: BUG #16018: pg_sequence_last_value() doesn't give results for owners - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #16018: pg_sequence_last_value() doesn't give results for owners
Date
Msg-id 9246.1569282009@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #16018: pg_sequence_last_value() doesn't give results for owners  (Robert Treat <rob@xzilla.net>)
List pgsql-bugs
Robert Treat <rob@xzilla.net> writes:
> On Mon, Sep 23, 2019 at 6:34 PM David G. Johnston
> <david.g.johnston@gmail.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
lastvalue handed out from the sequence. Null if the sequence has not been read from yet. Also, if the current user does
nothave 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



pgsql-bugs by date:

Previous
From: Robert Treat
Date:
Subject: Re: BUG #16018: pg_sequence_last_value() doesn't give results for owners
Next
From: Ashesh Vashi
Date:
Subject: Re: Query tool won't load