title: Do databases always lock non-existent rows after a query or update?
body: <p>Given:</p>
  
  <p><code>customer[id BIGINT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(30), count INT]</code></p>
  
  <p>I'd like to execute the following atomically: Update the customer if he already exists; otherwise, insert a new customer.</p>
  
  <p>In theory this sounds like a perfect fit for <a href="http://en.wikipedia.org/wiki/Merge_(SQL)" rel="nofollow noreferrer">SQL-MERGE</a> but the database I am using doesn't support <a href="https://stackoverflow.com/a/6307884/14731">MERGE with AUTO_INCREMENT columns</a>.</p>
  
  <p><a href="https://stackoverflow.com/a/1727788/14731">https://stackoverflow.com/a/1727788/14731</a> seems to indicate that if you execute a query or update statement against a non-existent row, the database will lock the index thereby preventing concurrent inserts.</p>
  
  <p>Is this behavior guaranteed by the SQL standard? Are there any databases that do not behave this way?</p>
  
  <p><strong>UPDATE</strong>: Sorry, I should have mentioned this earlier: the solution must use READ_COMMITTED transaction isolation <em>unless</em> that is impossible in which case I will accept the use of SERIALIZABLE.</p>