Liquibase does not add interval to current_timestamp

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.

Upvotes: 0

Views: 1073

Answers (1)

user330315
user330315

Reputation:

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.

Upvotes: 3

Related Questions