postgresql duplicate key violates unique constraint

Robby Russell wrote in post #72333:

...

SELECT MAX(id) FROM entities;
SELECT nextval('entities_id_seq');

This should be higher than the last result.
SELECT setval('entities_id_seq', (SELECT MAX(id) FROM entities)+1);

...

Thank you so much fro this post!