A
A
AE422020-11-26 19:39:05
PostgreSQL
AE42, 2020-11-26 19:39:05

Lock on Insert?

Good evening!

There is a games table, all new games are created in it (insert)
| id | creator_id | ... |

How to correctly lock the table/user action so that there is no race condition?
Because sometimes when creating a game, 2 identical ones are created.
When blocked, other requests for creation should be processed normally

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-11-26
@galaxy

Best of all is unique constraint.
If not, then pg_advisory_lock() .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question