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