title: Atomic UPDATE .. SELECT in Postgres
body: <p>I'm building a queuing mechanism of sorts. There are rows of data that need processing, and a status flag. I'm using an <code>update .. returning</code> clause to manage it:</p>
  
  <pre><code>UPDATE stuff
  SET computed = 'working'
  WHERE id = (SELECT id from STUFF WHERE computed IS NULL LIMIT 1)
  RETURNING * 
  </code></pre>
  
  <p>Is the nested select part the same lock as the update, or do I have a race condition here? If so, does the inner select need to be a <code>select for update</code>?</p>