I have a problem, when inserting a new row in the table I get the error: "duplicate key violates unique constraint".
After some analysis, I found this solution that helps to find out that the sequence is out of sync.
I used these two queries to find out if my id is out of sync:
SELECT MAX(id) FROM schema.table t; -- Value: 456
SELECT nextval(PG_GET_SERIAL_SEQUENCE('"table"', 'id')); -- Value: 462
They say that if the ID of the first query is greater than the ID of the second, it is out of sync.
But in my case, the ID of the first one is lower than the ID of the second one.
What can I conclude from here and how can I resolve my error when inserting a newline?
Note:
select * from pg_sequences;
With this query, I just discovered that I have 2 sequences with the same name: one is table_id_seq and another is table_id_seq1, could this be a problem?