I must / have to create unique ID for invoices. I have a table id and another column for this unique number. I use serialization isolation level. Using
var
You could create a sequence with no cache , then get the next value from the sequence and use that as your counter.
CREATE SEQUENCE invoice_serial_seq START 101 CACHE 1; SELECT nextval('invoice_serial_seq');
More info here