E
E
Evgeny Samsonov2019-05-17 23:19:23
MySQL
Evgeny Samsonov, 2019-05-17 23:19:23

How to make sure that INSERT is executed on the result of SELECT atomically?

It is necessary to perform an INSERT if the result of the SELECT is empty. The SELECT checks for the intersection of the date period with the existing periods of the table, so it will not be possible to set a unique key.
How to make the operation pass atomically so that several processes at the same time cannot add intersecting periods?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vadim, 2019-05-17
@bitniks

If the table type allows, use a transaction

S
SagePtr, 2019-05-17
@SagePtr

To check intersection in the trigger for addition, for example.

L
Lazy @BojackHorseman MySQL, 2019-05-18
Tag

LOCK TABLES

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question