[英]H2 Database - on primary key conflict replace
I would like to make the H2 Database engine replace the conflicting entriy if a entry is being inserted and it conflicts with another record having the same PRIMARY KEY or UNIQUE value. 如果要插入一个条目,并且与具有相同PRIMARY KEY或UNIQUE值的另一个记录发生冲突,我想让H2数据库引擎替换冲突的对象。
I can do the same in SQLite with the following: 我可以在SQLite中执行以下操作:
CREATE TABLE STACKOVERFLOW(FOO TEXT IDENTITY ON CONFLICT REPLACE);
This is called a conflict clause in SQLite. 这在SQLite中称为冲突子句 。
Can I replicate this behaviour in the H2 SQL dialect? 我可以在H2 SQL方言中复制此行为吗?
This can be achieved by using the MERGE INTO
statement, in my case I was able to just replace the INSERT
statement with MERGE INTO
: 这可以通过使用
MERGE INTO
语句来实现,在我的情况下,我可以将INSERT
语句替换为MERGE INTO
:
MERGE INTO TABLE STACKOVERFLOW('abc');
MERGE INTO TABLE STACKOVERFLOW('abc'); -- will not fail
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.