h2根据表中的当前列创建计算列

时间:2013-02-14 09:10:31

标签: h2

我有一个非常奇怪的问题,我认为,我希望根据同一个表中的当前列来计算现有列。现有列类型为“DATE”,另一列为“Datetime”。我使用查询“ALTER TABLE TEST ALTER COLUMN'date'AS CONVERT('last_date',DATE)”。 我总是遇到异常:org.h2.jdbc.JdbcSQLException:SQL语句中的语法错误“ALTER TABLE TEST ALTER COLUMN'date'[*] AS CONVERT('last_date',DATE)”;预期的“标识符”; ...

等待任何想法。

1 个答案:

答案 0 :(得分:3)

H2 SQL grammar for alter table不同。尝试:

drop table test;
create table test("last_date" timestamp, "date" timestamp);
alter table test alter column "date" timestamp 
    as convert("last_date", date);

drop table test;
create table test(last_date timestamp, date timestamp);
alter table test alter column date timestamp 
    as convert(last_date, date);