PostgreSQL Check Constraint in Liquibase

假装没事ソ 提交于 2019-12-05 12:23:32

This should be the way:

     <column name="int_value" type="INT" >
        <constraints checkConstraint="CHECK (int_value &gt;= 0 AND int_value &lt;= 6)"/>
    </column>

However, current Liquibase (3.5.1) ignores checkConstraint attribute. There is a pull request, but it is added only to 4.0 milestone.

Thus, we have to use the raw sql for check constraints for the time being. This works for me:

<createTable tableName="test">
     <column name="int_value" type="INT"/>
</createTable>
<sql>
    ALTER TABLE test ADD CONSTRAINT int_check CHECK (int_value &gt;=0 AND int_value &lt;= 6)
</sql>
<sql endDelimiter="\nGO">
  ALTER TABLE table_name ADD CONSTRAINT check_name CHECK (int_value &gt;=0 AND int_value &lt;= 6)
</sql>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!