我使用 postgres 数据库,我遇到了 liquibase 将时间间隔添加到当前时间作为默认值的问题:
<property name="expired" value="current_timestamp + interval '60 days'"
dbms="postgresql"/>
<addColumn tableName="user">
<column name="expired" type="timestamp"
defaultValueDate="${expired}">
<constraints nullable="false"/>
</column>
</addColumn>
Expired 属性总是返回当前日期而不添加 60 天。 是否可以?还是值域有误? 提前谢谢你。
最佳答案
您需要对表达式使用 defaultValueComputed
。
但显然 Liquibase 中存在一个错误,导致它无法正确解析带有 current_timestamp
的表达式。但是使用 now()
似乎可行:
<property name="expired" value="now() + interval '60 days'" dbms="postgresql"/>
<addColumn tableName="user">
<column name="expired" type="timestamp" defaultValueComputed="${expired}">
<constraints nullable="false"/>
</column>
</addColumn>
无关,但是:user
是保留关键字。使用该名称创建表是一个非常糟糕的主意。
关于postgresql - Liquibase 不会将间隔添加到 current_timestamp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52512435/