setval in postgres 1

setval in postgres

SELECT setval('tbl_tbl_id_seq', max(tbl_id)) FROM tbl;

Here is what the above code is Doing:
1. It’s creating a sequence called tbl_tbl_id_seq.
2. It’s setting the next value of the sequence to be the maximum value of the tbl_id column in the tbl table.

Similar Posts