Liquibase does not add interval to current_timestamp

北慕城南 提交于 2021-01-29 08:37:50

问题


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 property always returns current date without adding 60 days. Is it possible? Or is there some mistakes in value field? Thank you in advance.


回答1:


You need to use defaultValueComputed for an expression.

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>

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



来源:https://stackoverflow.com/questions/52512435/liquibase-does-not-add-interval-to-current-timestamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!