pg_get_sequence_data Shows Non-NULL last_value for Freshly Created Sequence - Mailing list pgsql-hackers

From vignesh C
Subject pg_get_sequence_data Shows Non-NULL last_value for Freshly Created Sequence
Date
Msg-id CALDaNm36PKfjSJPQWFi1kB832zhkDxyyFCLkg1x39Sz+eikRaw@mail.gmail.com
Whole thread Raw
Responses Re: pg_get_sequence_data Shows Non-NULL last_value for Freshly Created Sequence
List pgsql-hackers
Hi,

I noticed an inconsistency in the behavior of sequence-related
functions for a freshly created sequence.
CREATE SEQUENCE s1;

postgres=# select last_value from pg_sequences;
 last_value
------------

(1 row)

postgres=# select pg_sequence_last_value('s1');
 pg_sequence_last_value
------------------------

(1 row)

postgres=# select las_value from pg_get_sequence_data('s1');
 last_value
------------
          1
(1 row)

As you can see:

pg_sequences and pg_sequence_last_value return NULL for last_value,
which aligns with the expectation that the sequence hasn't been used
yet. However, pg_get_sequence_data returns the start value (1) even
though is_called is false. This seems inconsistent. I felt
pg_get_sequence_data should also return NULL for last_value in this
case to match the others.
Attached patch has a fix for the same. Thoughts?

Regards,
Vignesh

Attachment

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: VM corruption on standby
Next
From: Nathan Bossart
Date:
Subject: Re: Reduce "Var IS [NOT] NULL" quals during constant folding