我正在根据这篇很棒的帖子实施 upsert:Insert, on duplicate update in PostgreSQL? 这对 psql 非常有效。但是,我无法将相同的查询触发到我用于测试的 hsqldb 中。我的 sql 看起来像这样:
UPDATE account set name = ?, email = ?, type = ?, regts = ?, dao_updated = ? WHERE id = ?;
INSERT INTO account (id, name, email, type, regts, dao_created,dao_updated) SELECT ?,?,?,?,?,?,? WHERE NOT EXISTS (SELECT 1 FROM account WHERE id = ? );
我收到错误消息:
Caused by: java.sql.SQLSyntaxErrorException: unexpected token: INSERT
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
这是 hsqldb 的限制还是我做错了什么?
提前感谢莱昂