I want to select fields in a record of a table and update just 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 it sets field "schedulingflag" true in all record!
FOR SHARE , which provides a weaker form of row-locking in some database systems. In PostgreSQL, SELECT … FOR UPDATE completely locks the relevant rows, whereas SELECT … FOR SHARE locks the relevant rows only for updates and deletes.
PostgreSQL SELECT Syntax The simplest form of the SELECT statement syntax is: SELECT expressions FROM tables WHERE conditions; The expressions are all the columns and fields you want in the result. The tables syntax is the table or tables from which you want to extract the results.
PostgreSQL implements multiversioning by keeping the old version of the table row in the table – an UPDATE adds a new row version (“tuple”) of the row and marks the old version as invalid. In many respects, an UPDATE in PostgreSQL is not much different from a DELETE followed by an INSERT .
The SELECT FOR UPDATE
syntax tells PG that you're going to be updating those records and locks them against concurrent access. However you still need to issue the appropriate UPDATE
call to change the particular records you've locked.
In this case, just use the same WHERE
clause in your UPDATE
, e.g:
UPDATE video SET schedulingflag = true
WHERE schedulingflag IS FALSE AND errorflag IS FALSE;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With