S
S
svet12017-05-11 09:04:16
PostgreSQL
svet1, 2017-05-11 09:04:16

Why are there duplicates in Postgres on multiple inserts?

There is an application that collects data at a certain interval, processes it and inserts it into the database (about 2000+ values ​​at a time).
When an entity is inserted, a field check is made to see if there is one already in the database, and if so, do nothing.
When checking for uniqueness (after some time), it turned out that there are duplicates (1 per 100 inserts approximately): identical lines with an insert difference in milliseconds.
Previously, the check was in a SQL query (INSERT SELECT IS NOT EXIT), later it was taken out to the application (id is searched by parameters, if it is not there, then insert). But the duplicates remain.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Shelemetiev, 2017-05-11
@zoroda

The problem is concurrent access to data .
This can be controlled, but it would be smarter to return data integrity control to the PostgreSQL engine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question