Florian Weimer <fw@deneb.enyo.de> writes:
> Is this a bug, or is SQLxx serializability defined in different terms?
Strictly speaking, we do not guarantee serializability because we do not
do predicate locking. See for example
http://archives.postgresql.org/pgsql-general/2003-01/msg01581.php
AFAIK, no commercial database does predicate locking either, so we all
fall short of true serializability. The usual solution if you need the
sort of behavior you're talking about is to take a non-sharable write
lock on the table you want to modify, so that only one transaction can
do the COUNT/INSERT at a time.
regards, tom lane