"Andrew G. Hammond" <drew@xyzzy.dhs.org> writes:
> Is this correct behaviour? ACID compliant? The argument in it's favour it
> pretty obvious: if you never go backwards then you'll never get an accidental
> duplication as follows:
>
> t1 BEGIN; SELECT nextval('test_id_seq') # 1
> t2 SELECT nextval('test_id_seq') # 2
> t1 ROLLBACK # test_id_seq decremented
> t3 SELECT nextval('test_id_seq') # 2
>
> However wouldn't locking the sequence be more proper behaviour?
As I understand it, this is one case where efficiency wins out--if you
locked the sequence some apps could end up with a lot of lock
contention. So we don't lock, don't roll back and work fine except
that there can be gaps in a SERIAL column.
I don't think sequences are in the SQL standard so we're not really
violating anything. ;)
-Doug
--
Let us cross over the river, and rest under the shade of the trees.
--T. J. Jackson, 1863