Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iCXwG-0005lh-Gu for pgsql-bugs@arkaria.postgresql.org; Mon, 23 Sep 2019 23:40:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iCXwF-0002jP-7U for pgsql-bugs@arkaria.postgresql.org; Mon, 23 Sep 2019 23:40:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iCXwE-0002jI-TM for pgsql-bugs@lists.postgresql.org; Mon, 23 Sep 2019 23:40:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iCXwC-0007Wb-Gm for pgsql-bugs@lists.postgresql.org; Mon, 23 Sep 2019 23:40:13 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x8NNe9t6009248; Mon, 23 Sep 2019 19:40:09 -0400 From: Tom Lane To: Robert Treat cc: PostgreSQL mailing lists Subject: Re: BUG #16018: pg_sequence_last_value() doesn't give results for owners In-reply-to: References: <16018-e617465560d648c5@postgresql.org> Comments: In-reply-to Robert Treat message dated "Mon, 23 Sep 2019 19:34:03 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9245.1569282009.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 23 Sep 2019 19:40:09 -0400 Message-ID: <9246.1569282009@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Robert Treat writes: > On Mon, Sep 23, 2019 at 6:34 PM David G. Johnston > wrote: >> From pg_sequences: >> last_value bigint The last sequence value written to disk. If caching i= s 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 cu= rrent user does not have USAGE or SELECT privilege on the sequence, the va= lue 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