1

I created a table with a SERIAL column but I also manually inserted some rows. I need to update the SERIAL so it goes to the next one.

pathikrit
  • 30,920
  • 35
  • 134
  • 215

1 Answers1

1

Let's say your sequence is named $seq. If you used the SERIAL to create the table:

CREATE TABLE foo {id SERIAL, .... }

the sequence would be called something like foo_id_seq

Do this:

SELECT setval('foo_id_seq', (SELECT max(id) FROM foo), TRUE)
pathikrit
  • 30,920
  • 35
  • 134
  • 215