简体   繁体   English

H2 数据库 Postgres 模式 Upsert

[英]H2 Database Postgres Mode Upsert

When H2 database is in Postgres Mode, how do I check if it supports following statement (upsert / on conflict)当 H2 数据库处于 Postgres 模式时,如何检查它是否支持以下语句(upsert / on conflict)

INSERT INTO event_log_poller_state (aggregate_type, consumer_group_id, value) 
VALUES (?, ?, ?) 
on conflict (aggregate_type, consumer_group_id) " +
                    " do update SET VALUE = ? 
WHERE
  event_log_poller_state.aggregate_type = ? AND
  event_log_poller_state.consumer_group_id = ?

I get syntax error 42000我收到语法错误 42000

I're written following program to demonstrate我写了以下程序来演示

https://github.com/tonymurphy/h2-postgres https://github.com/tonymurphy/h2-postgres

Edit Oct 2019: Checkout https://github.com/whisklabs/docker-it-scala or testcontainers.org 2019 年 10 月编辑:结帐https://github.com/whisklabs/docker-it-scala或 testcontainers.org

There is merge which should do the same: https://www.tutorialspoint.com/h2_database/h2_database_merge.htm有合并应该做同样的事情: https://www.tutorialspoint.com/h2_database/h2_database_merge.htm

MERGE INTO tableName [ ( columnName [,...] ) ] 
[ KEY ( columnName [,...] ) ] 
{ VALUES { ( { DEFAULT | expression } [,...] ) } [,...] | select } 

See also https://github.com/h2database/h2database/issues/2007#issuecomment-1152312049另请参阅https://github.com/h2database/h2database/issues/2007#issuecomment-1152312049

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM