Roman
Roman

Reputation: 11

postgresql nextval incorrect result

After restoring database I run next query

SELECT nextval('table_id_seq') 

and I must get max id + 1 something like (select max(id) + 1 from table), but instead I get just max id next time I call it result is correct. This issue happens only to two tables the rest works okay. I use PostgreSQL 10.

Any ideas what it can be.

Upvotes: 1

Views: 2292

Answers (1)

Anoop Sharma
Anoop Sharma

Reputation: 399

Check "last value" of sequence using below query:

select * from sequence_name

If the last value does not match with table max value then use alter sequence and restart the last value as table max value.

Upvotes: 2

Related Questions