[COLUG] Postgres SERIAL field

Mark Erbaugh mark at microenh.com
Fri Dec 28 15:43:34 EST 2007


A SERIAL field in Postgres is implemented as a field with a default
value from a sequence generator, thus it allows you to insert records
with a pre-existing value for the serial field.  However, the underlying
sequence generator is not updated when such a record is inserted.

Is there a way to automatically update the sequence after inserting
records with pre-existing values for the field? I have tried

alter sequence x restart with (select max(field) from table);

which results in syntax error at or near "("'

I am able to do

alter sequence x restart with #

where # is a number that I get from doing select max(field) from table;

Mark



More information about the colug432 mailing list