Skip to content

Instantly share code, notes, and snippets.

@niktto
Last active December 14, 2015 02:19
Show Gist options
  • Save niktto/5013175 to your computer and use it in GitHub Desktop.
Save niktto/5013175 to your computer and use it in GitHub Desktop.
LOCK TABLE {table} IN ACCESS EXCLUSIVE MODE;
UPDATE {table} SET status = 1, thread_id = 1
WHERE id IN (
SELECT id FROM {table} WHERE status = 0
ORDER BY creation_date DESC, user_id ASC
LIMIT 100)
RETURNING 'id', 'user_id', 'creation_date', 'modification_date', 'thread_id', 'reason', 'status';
Or from statement log:
2013-02-22 08:01:45 EST LOG: statement: BEGIN
2013-02-22 08:01:45 EST LOG: statement: LOCK TABLE email_queue IN ACCESS EXCLUSIVE MODE; UPDATE email_queue SET statu
s = 1, thread_id = 'taskworkshop.com_8912' WHERE id IN (SELECT id FROM email_queue WHERE status = 0 ORDER BY creation_
date DESC, priority DESC, user_id ASC LIMIT 100) RETURNING id, user_id, subject, template_prefix, template_context, cr
eation_date, modification_date, priority, thread_id, reason, status;
2013-02-22 08:01:45 EST LOG: statement: COMMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment