title: How to use RETURNING with ON CONFLICT in PostgreSQL?
body: <p>I have the following UPSERT in PostgreSQL 9.5:</p>
  
  <pre><code>INSERT INTO chats ("user", "contact", "name") 
             VALUES ($1, $2, $3), 
                    ($2, $1, NULL) 
  ON CONFLICT("user", "contact") DO NOTHING
  RETURNING id;
  </code></pre>
  
  <p>If there are no conflicts it returns something like this:</p>
  
  
  
  <pre class="lang-none prettyprint-override"><code>----------
      | id |
  ----------
    1 | 50 |
  ----------
    2 | 51 |
  ----------
  </code></pre>
  
  <p>But if there are conflicts it doesn't return any rows:</p>
  
  <pre class="lang-none prettyprint-override"><code>----------
      | id |
  ----------
  </code></pre>
  
  <p>I want to return the new <code>id</code> columns if there are no conflicts or return the existing <code>id</code> columns of the conflicting columns.<br>
  <strong>Can this be done?</strong> If so, <strong>how?</strong></p>