Liquibase 不会将间隔添加到 current_timestamp

Liquibase does not add interval to current_timestamp

我使用 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>

已过期 属性 始终 returns 当前日期未添加 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是保留关键字。使用该名称创建 table 是一个非常糟糕的主意。