title: Get Id from a conditional INSERT
body: <p>For a table like this one:           </p>
  
  <pre><code>CREATE TABLE Users(
      id SERIAL PRIMARY KEY,
      name TEXT UNIQUE
  );
  </code></pre>
  
  <p>What would be the correct one-query insert for the following operation:</p>
  
  <p>Given a user <code>name</code>, insert a new record and return the new <code>id</code>. But if the <code>name</code> already exists, just return the <code>id</code>.</p>
  
  <p>I am aware of the new syntax within PostgreSQL 9.5 for <code>ON CONFLICT(column) DO UPDATE/NOTHING</code>, but I can't figure out how, if at all, it can help, given that I need the <code>id</code> to be returned. </p>
  
  <p>It seems that <code>RETURNING id</code> and <code>ON CONFLICT</code> do not belong together.</p>