Select for Update statement in PostgreSql

I want to select fields in the recor table and update only one of these fields. How can i do

I try this:

SELECT v.idvideo, v.title 
FROM video v  WHERE v.schedulingflag IS FALSE AND v.errorflag IS FALSE 
ORDER BY v.idvideo  LIMIT 1 FOR UPDATE ;

UPDATE video  SET schedulingflag = true;

But in this way he sets the "schedulingflag" field to true in the whole record!

+5
source share
1 answer

The syntax SELECT FOR UPDATEtells PG that you are about to update these records and block them from being accessed simultaneously. However, you still need to issue an appropriate call UPDATEto modify certain entries that you have blocked.

In this case, just use the same WHEREsentence in UPDATE, for example:

UPDATE video  SET schedulingflag = true 
WHERE schedulingflag IS FALSE AND errorflag IS FALSE;
+12
source

All Articles