June 6, 2024, 6:03 a.m. | Jack

DEV Community dev.to




What is "SELECT FOR UPDATE"?


SELECT FOR UPDATE is a clause in SQL that is appended to a SELECT statement. It locks the selected rows, preventing other transactions from modifying them until the current transaction is committed or rolled back. This ensures that the data being read and potentially updated remains consistent throughout the transaction.





Syntax of "SELECT FOR UPDATE"


The basic syntax for using "SELECT FOR UPDATE" is:



BEGIN;
SELECT stock
FROM items
WHERE item_id = ?
FOR UPDATE; …

consistent current data database postgres sql them transactions understanding update

Senior Data Engineer

@ Displate | Warsaw

Automation and AI Strategist (Remote - US)

@ MSD | USA - New Jersey - Rahway

Assistant Manager - Prognostics Development

@ Bosch Group | Bengaluru, India

Analytics Engineer - Data Solutions

@ MSD | IND - Maharashtra - Pune (Wework)

Jr. Data Engineer (temporary)

@ MSD | COL - Cundinamarca - Bogotá (Colpatria)

Senior Data Engineer

@ KION Group | Atlanta, GA, United States