<p dir="auto"><strong>Migrated issue, originally created by Adrian (<a href="https://github.com/thiefmaster">@thiefmaster</a>)</strong></p>
<p dir="auto">Probably a bit early since 9.5 isn't out yet, but once it's out this would be pretty useful.</p>
<p dir="auto"><a href="https://wiki.postgresql.org/wiki/What's_new_in_PostgreSQL_9.5#INSERT_..._ON_CONFLICT_DO_NOTHING.2FUPDATE_.28.22UPSERT.22.29" rel="nofollow">https://wiki.postgresql.org/wiki/What's_new_in_PostgreSQL_9.5#INSERT_..._ON_CONFLICT_DO_NOTHING.2FUPDATE_.28.22UPSERT.22.29</a></p>
<p dir="auto">This could be a table arg, e.g. <code class="notranslate">postgres_onconflict='nothing|update'</code> (or maybe even in a less db-specific way if other databases also support this feature). When set it would automatically add it to INSERTs involving that table.</p>
<p dir="auto"><strong>Migrated issue, originally created by jek (<a href="https://github.com/jek">@jek</a>)</strong></p>
<p dir="auto">Implement generic MERGE, aka 'upsert'.  In ANSI, it looks like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="MERGE INTO table_name1 USING table_name2 ON (condition)
WHEN MATCHED THEN UPDATE SET column1 = value1 [column2 = value2 ...](,)
WHEN NOT MATCHED THEN INSERT columns VALUES (values) "><pre class="notranslate"><code class="notranslate">MERGE INTO table_name1 USING table_name2 ON (condition)
WHEN MATCHED THEN UPDATE SET column1 = value1 [column2 = value2 ...](,)
WHEN NOT MATCHED THEN INSERT columns VALUES (values) 
</code></pre></div>
<p dir="auto">Dialect support differs pretty widely.  A quick &amp; likely inaccurate poll:</p>
<ul dir="auto">
<li>Oracle 9+ has a MERGE</li>
<li>t-sql 2008 has a MERGE, earlier can maybe do <code class="notranslate">IF EXISTS(SELECT ...)</code></li>
<li>MySQL is limited to a key violation condition, and can do either <code class="notranslate">INSERT ... ON DUPLICATE KEY UPDATE</code> or <code class="notranslate">REPLACE INTO</code>, INSERT being preferable</li>
<li>SQLite is limited to a key violation condition, and has <code class="notranslate">INSERT .. ON CONFLICT REPLACE</code></li>
</ul>