Today I Learned

Jun 21, 2019 | 1 minute read

Today I learned about NOWAIT for PostgreSQL. This is an option for the SELECT FOR UPDATE command, allowing you to control the behavior of locking rows during a transaction. We use SELECT \* FROM table WHERE col = 'value' FOR UPDATE to provide exclusivity when updating certain objects in the database. Adding the NOWAIT option causes this statement to error and return immediately if the row is already locked, allowing the application to handle this case in a more interesting way than simply waiting indefinitely.