Liquibase不会将间隔添加到current_timestamp [英] Liquibase does not add interval to current_timestamp

查看:78
本文介绍了Liquibase不会将间隔添加到current_timestamp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用postgres DB,我遇到了一个问题,即liquibase向当前时间添加间隔作为默认值:

I use postgres DB, I faced an issue with liquibase adding interval to the current time as default value:

<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天.是否可以?还是价值领域存在一些错误?预先谢谢你.

Expired property always returns current date without adding 60 days. Is it possible? Or is there some mistakes in value field? Thank you in advance.

推荐答案

您需要对表达式使用 defaultValueComputed .

但是很明显,Liquibase中存在一个错误,阻止它正确解析带有 current_timestamp 的表达式.但是使用 now()似乎可行:

But apparently there is a bug in Liquibase that prevents it from parsing an expression with current_timestamp correctly. But using now() seems to work:

<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 是保留关键字.创建具有该名称的表是一个非常糟糕的主意.


Unrelated, but: user is a reserved keyword. It is a very bad idea to create a table with that name.

这篇关于Liquibase不会将间隔添加到current_timestamp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆