V
V
Valentine2018-02-15 17:14:14
PostgreSQL
Valentine, 2018-02-15 17:14:14

How to avoid auto-increment increase on unsuccessful request?

The users table has two unique fields login and email.
If you try to add a record where the login or email is not unique, the request will fail, the record will not be added, but auto-increment will add one. And the next successful id will be one more. How to avoid it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeniy Zavyalov, 2018-02-15
@valentinesowl

Check your username and email before proceeding. No => insert. Yes => error

M
Melkij, 2018-02-15
@melkij

No way.
The sequence is guaranteed to be unique and non-transactional. He does not say anything about the sequence of issuing values, and even more so without gaps.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question