postgres update sequence max id code example Example: postgres set sequence value to max id SELECT setval('table_id_seq', (SELECT MAX(id) FROM table));