Created
January 18, 2026 09:00
-
-
Save up1/4782f5471c938cec8ca1108d750d6156 to your computer and use it in GitHub Desktop.
Postgresql :: Skip Locked
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| WITH cte AS ( | |
| SELECT id FROM tasks WHERE status = 'pending' ORDER BY created_at ASC LIMIT 1 FOR UPDATE SKIP LOCKED | |
| ) | |
| UPDATE tasks SET status = 'in_progress' | |
| FROM cte | |
| WHERE tasks.id = cte.id | |
| RETURNING tasks.*; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment