Using setval('sequence',1) sets the start value of the sequence to 1. But when a record is inserted, the first 'sequence' number is actually 2.
How do I get the actual first record to have a sequence number of 1?
Using setval('sequence',1) sets the start value of the sequence to 1. But when a record is inserted, the first 'sequence' number is actually 2.
How do I get the actual first record to have a sequence number of 1?
From the fine manual:
So calling
setval('sequence', 1)sets the sequence's current value to1and the next value will be2. You probably want the three argument form ofsetval:so that the
is_calledflag on the sequence will be false andnextval('sequence')will be1. Also note that the default value for columns bound to sequences isnextval('sequence').