I'm using Postgres 9.5 and seeing some wired things here.
I've a cron job running ever 5 mins firing a sql statement that is adding a list of records if not existing.
INSERT INTO
sometable (customer, balance)
VALUES
(:customer, :balance)
ON CONFLICT (customer) DO NOTHING
sometable.customer is a primary key (text)
sometable structure is:
id: serial
customer: text
balance: bigint
Now it seems like everytime this job runs, the id field is silently incremented +1. So next time, I really add a field, it is thousands of numbers above my last value. I thought this query checks for conflicts and if so, do nothing but currently it seems like it tries to insert the record, increased the id and then stops.
Any suggestions?
SERIAL
/SEQUENCE
support is not what you should be using. See this answer from Craig Ringer. – Loupsmallserial
and the insert conflicts are blowing out the max size of thesmallint
even though in reality there are way fewer than 32k rows. With 32 parallel processes loading data, the conflicts reach the max within a few seconds... (this table has billions of rows, hence the desire to convert a ~100 char varchar down to asmallint
since there are only ~20k distinct values) – Tinaret