FOR UPDATE SKIP LOCKED
FOR UPDATE SKIP LOCKED is a SQL clause in the PostgreSQL Specific category. PostgreSQL: skip rows locked by other transactions (instead of waiting). Perfect for job queues. The syntax is SELECT ... FOR UPDATE SKIP LOCKED;. It returns rows with skip lock. A typical example: BEGIN; SELECT * FROM job_queue WHERE status = 'pending' ORDER BY priority FOR UPDATE SKIP LOCKED LIMIT 1; -- Picks next pending job, skipping any locked by other workers -- Ensures each job is processed by exactly one worker COMMIT; A close relative is SERIAL, which postgreSQL auto-increment type. Creates an INTEGER column with a sequence. Equivalent to AUTO_INCREMENT in MySQL. A close relative is RETURNING, which postgreSQL extension that returns values from INSERT/UPDATE/DELETE statements (like OUTPUT in SQL Server). A close relative is ARRAY, which postgreSQL supports array columns and array operations. Can be multi-dimensional. More about this category: PostgreSQL-specific features — SERIAL, RETURNING, ARRAY, JSONB, UPSERT.