You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by "jan (JIRA)" <em...@incubator.apache.org> on 2016/08/09 05:34:20 UTC

[jira] [Updated] (EMPIREDB-247) Add Support for "insertOrUpdate" ("UPSERT")

     [ https://issues.apache.org/jira/browse/EMPIREDB-247?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

jan updated EMPIREDB-247:
-------------------------
    Description: 
It should be possible to create a "insertOrUpdate" statement from a DBCommand and perform a "executeInsertOrUpdate" in DBDatabase.

This feature requires database dependent implementations. 

- for MySQL / MariaDB "INSERT ... ON DUPLICATE KEY UPDATE" (http://dev.mysql.com/doc/refman/5.5/en/insert-on-duplicate.html) can be used

- for Oracle "MERGE INTO" can be used

- for MSSQL merge should work, too

- for Postgres "INSERT ... ON CONFLICT UPDATE" (https://wiki.postgresql.org/wiki/UPSERT) can be used

DBDatabase.executeInsertOrUpdate could use something like

int count = db.executeUpdate(cmd, conn);
if (count < 1) {
	// nothing updated -> INSERT
	count += db.executeInsert(cmd, conn);
}
return count;

as fallback. I dont think a fallback is possible in DBCommand, so the default implementation should throw a NotSupportedException.

The DBDriverFeature should be extended by PERFORM_INSERT_OR_UPDATE or maybe PERFORM_UPSERT.

> Add Support for "insertOrUpdate" ("UPSERT")
> -------------------------------------------
>
>                 Key: EMPIREDB-247
>                 URL: https://issues.apache.org/jira/browse/EMPIREDB-247
>             Project: Empire-DB
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: empire-db-2.4.4
>            Reporter: jan
>            Priority: Minor
>
> It should be possible to create a "insertOrUpdate" statement from a DBCommand and perform a "executeInsertOrUpdate" in DBDatabase.
> This feature requires database dependent implementations. 
> - for MySQL / MariaDB "INSERT ... ON DUPLICATE KEY UPDATE" (http://dev.mysql.com/doc/refman/5.5/en/insert-on-duplicate.html) can be used
> - for Oracle "MERGE INTO" can be used
> - for MSSQL merge should work, too
> - for Postgres "INSERT ... ON CONFLICT UPDATE" (https://wiki.postgresql.org/wiki/UPSERT) can be used
> DBDatabase.executeInsertOrUpdate could use something like
> int count = db.executeUpdate(cmd, conn);
> if (count < 1) {
> 	// nothing updated -> INSERT
> 	count += db.executeInsert(cmd, conn);
> }
> return count;
> as fallback. I dont think a fallback is possible in DBCommand, so the default implementation should throw a NotSupportedException.
> The DBDriverFeature should be extended by PERFORM_INSERT_OR_UPDATE or maybe PERFORM_UPSERT.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)