为什么此UPDATE语句在H2中失败?

时间:2019-11-22 13:10:29

标签: sql h2

此UPDATE语句在针对Postgres运行时有效,但在针对H2运行时失败。等价的H2语句是什么?

UPDATE award_details
SET award_id = a.id
FROM awards a
WHERE a.award_details_id = award_details.id;

H2错误消息是:

SQL State  : 42000
Error Code : 42000
Message    : Syntax error in SQL statement "​​[*]
UPDATE AWARD_DETAILS
SET AWARD_ID = A.ID
FROM AWARDS A
WHERE A.AWARD_DETAILS_ID = AWARD_DETAILS.ID"; SQL statement:

1 个答案:

答案 0 :(得分:2)

您当前的更新语法看起来是Postgres风格。而是使用相关的子查询更新语法:

UPDATE award_details aw
SET award_id = (SELECT a.id FROM awards a WHERE a.award_details_id = aw.id);