restart so that nextval is the next unused id

Viewed 8694

I've got a script which copies table data from one DB to another, however the ID column is backed by a sequence so when a new record is inserted into the destination table the nextval(seq) is returning the wrong value.

I need to update the sequence so that it starts at the next available ID.

I want to do something like:

ALTER SEQUENCE seq_id RESTART WITH
    (SELECT MAX(id) FROM tbl);

The above produces a syntax error however.

Can anyone suggest an alternative approach?

1 Answers
Related