Having a simple table structure like this:
CREATE TABLE test (
id INT PRIMARY KEY,
sid SERIAL
);
I noticed if I attempt to insert a row but it fails a constraint test (i.e. PRIMARY KEY constraint), the SERIAL counter will increment anyway, so the next successful insert, sid will be sid + 2 instead of sid + 1.
Is this normal behavior? Any way to prevent this?