Handling race conditions in PostgreSQL
问题 I have several workers, each holding its own connection to PostgreSQL. The workers manipulate with different tables. The workers handle parallel requests from outside the system. One of the tables being accessed is the table of users. When some information comes, I first need to ensure there is a record for the user in the table. If there is no record, I wish to create one at first. I'm using the following idiom: if [user does not exist] then [create user] The code of [user does not exist] is