I use a query like this:
INSERT INTO table
SELECT * FROM table2 t2
JOIN ...
...
WHERE table2.date < now() - '1 day'::INTERVAL
FOR UPDATE OF t2 SKIP LOCKED
ON CONFLICT (...)
DO UPDATE SET ...
RETURNING *;
My question is about FOR UPDATE t2 SKIP LOCKED
. Should I use it here? Or will Postgres lock these rows automatically with INSERT SELECT ON CONFLICT
till the end of the transaction?
My goal is to prevent other apps from (concurrently) capturing rows with the inner SELECT
which are already captured by this one.