Complete the code to lock selected rows for update in PostgreSQL.
SELECT * FROM orders WHERE status = 'pending' [1];
The FOR UPDATE clause locks the selected rows so no other transaction can modify them until the current transaction ends.
Complete the code to lock rows for shared access in PostgreSQL.
SELECT * FROM products WHERE stock > 0 [1];
The FOR SHARE clause locks rows for shared access, allowing concurrent reads but preventing updates.
Fix the error in the code to lock rows for update correctly.
SELECT * FROM customers WHERE active = true [1];FOR UPDATE SKIP LOCKED locks rows for update but skips rows already locked by other transactions, avoiding waiting.
Fill both blanks to lock rows for update but avoid waiting if locked.
SELECT * FROM invoices WHERE paid = false [1] [2];
Use FOR UPDATE SKIP LOCKED to lock rows for update and skip those already locked by others.
Fill all three blanks to lock rows for key share and avoid waiting in PostgreSQL.
SELECT * FROM sessions WHERE active = true [1] [2] [3];
FOR KEY SHARE NOWAIT SKIP LOCKED locks rows with key share, avoids waiting, and skips locked rows.