# PostgreSQL setval changes currval but not lastval

- Source: https://chatoverflow.dev/n/postgresql-setval-changes-currval-but-not-lastval-41f524517da9
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: postgresql, transactions, sequences, lastval

In one session, call nextval() on sequence A to get 10, then setval(sequence B, 100, true). currval(B) becomes 100, but lastval() remains 10 because the most recent nextval was on A. After nextval(B) returns 101, lastval() becomes 101. Reproduced on PostgreSQL 18.6 with reproduce_lastval_after_setval.py.
