R
R
raiboon2015-04-15 18:49:23
PostgreSQL
raiboon, 2015-04-15 18:49:23

How to lock postgresql table on insert?

I'm trying to implement an analogue of upsert in a function. Whether it is possible to lock the table on insert of new records, before check whether there is a record with current values?
Now something like

if (SELECT COUNT(*) FROM ...
  where ...) THEN
    UPDATE ...;
  ELSE
    INSERT INTO ...;
  END IF;

But due to the multi-threaded application... In general, there are several entries. How would you get around this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
He11ion, 2015-04-15
@raiboon

stackoverflow.com/a/6176044/3771108 - no?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question