On Fri, Jun 27, 2025 at 8:50 AM shveta malik <shveta.malik@gmail.com> wrote:
>
> On Wed, Jun 25, 2025 at 7:42 PM Shlok Kyal <shlok.kyal.oss@gmail.com> wrote:
> > Hi Vignesh,
> >
> > I tested with all patches applied. I have a comment:
> >
> > Let consider following case:
> > On publisher create a publication pub1 on all sequence. publication
> > has sequence s1. The curr value of s1 is 2
> > and On subscriber we have subscription on pub1 and sequence s1 has
> > value 5. Now we run:
> > "ALTER SUBSCRIPTION sub1 REFRESH PUBLICATION SEQUENCES"
> >
> > Now on subscriber currval still show '5':
> > postgres=# select currval('s1');
> > currval
> > ---------
> > 5
> > (1 row)
> >
> > But when we do nextval on s1 on subscriber we get '3'. Which is
> > correct assuming sequence is synced:
> > postgres=# select nextval('s1');
> > nextval
> > ---------
> > 3
> > (1 row)
> > postgres=# select currval('s1');
> > currval
> > ---------
> > 3
> > (1 row)
> >
> > Is this behaviour expected? I feel the initial " select
> > currval('s1');" should have displayed '2'. Thoughts?
>
> As per docs at [1], currval returns the value most recently obtained
> by nextval for this sequence in the current session. So behaviour is
> in alignment with docs. I tested this across multiple sessions,
> regardless of whether sequence synchronization occurs or not. The
> behavior remains consistent across sessions. As an example, if in
> session2 the sequence has advanced to a value of 10 by calling
> nextval, the currval in session1 still shows the previous value of 3,
> which was obtained by nextval in session1. So, it seems expected to
> me. But let's wait for Vignesh's comments on this.
>
> [1]: https://www.postgresql.org/docs/current/functions-sequence.html
>
I also agree. It is expected behavior, as currval returns the last
nextval generated in the same session. I've also observed this across
multiple sessions.
--
Thanks,
Nisha