Postgres 9.5+: UPSERT to return the count of updated and inserted rows : <p>I get the canonical example:</p>

<pre><code> INSERT INTO user_logins (username, logins)
 VALUES ('Naomi',1),('James',1)
 ON CONFLICT (username)
 DO UPDATE SET logins = user_logins.logins + EXCLUDED.logins;
</code></pre>

<p>But now I also need to know:</p>

<ol>
<li>How many rows were inserted</li>
<li>How many rows were updated because existing</li>
<li>How many rows could not be inserted because of constraints</li>
<li>If the constraint is not respected for the last row, will the previous inserted/updated rows be persisted in the DB? </li>
</ol>
