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