Say I have the following table things. I want unique names in the table so there are no duplicates. The process that inserts a thing shouldn't need to check if a thing with this name is already there.
CREATE TABLE things(
id SMALLSERIAL PRIMARY KEY,
name varchar UNIQUE
);
When I insert values like this it works. If 'desk' is already in things it won't be inserted.
INSERT INTO things (name)
VALUES ('desk')
ON CONFLICT DO NOTHING;
Tho only problem is ON CONFLICT DO NOTHING does not really do nothing. It still increments the sequence for the id field.
If this happens too often the id sequence eventually gets too big for the field type.
Is there a way to prevent this from happening?