【问题标题】:How to build a WHERE-clause in a LiquiBase changeset如何在 LiquiBase 变更集中构建 WHERE 子句
【发布时间】:2014-09-30 22:24:44
【问题描述】:
如何在“LiquiBase”表示法中定义一个变更集,以更新带有 AND 的 WHERE 子句的表列:
<changeSet id="ddl update tables : modify datatype for MY_TABLE.STATE_ABBREV" author="xxx">
<preConditions onFail="MARK_RAN" onFailMessage="Column MY_TABLE.STATE_ABBREV doesn't exists.">
<and>
<tableExists tableName="MY_TABLE"/>
<columnExists tableName="MY_TABLE" columnName="STATE_ABBREV"/>
</and>
</preConditions>
<update tableName="MY_TABLE">
<column name="STATE_ABBREV" value="AS"/>
<where>AGU /***AND STATE_ID=3***/ ??????????????????
</where>
</update>
</changeSet>
【问题讨论】:
标签:
where-clause
liquibase
changeset
【解决方案1】:
您在<where> 标记中添加的内容只是简单地附加到UPDATE 语句末尾的“WHERE”之后。你可以把任何东西放在你通常放在 SQL 中的 where 标记中。
例子:
<changeSet id="ddl update tables : modify datatype for MY_TABLE.STATE_ABBREV" author="xxx">
<preConditions onFail="MARK_RAN" onFailMessage="Column MY_TABLE.STATE_ABBREV doesn't exists.">
<and>
<tableExists tableName="MY_TABLE"/>
<columnExists tableName="MY_TABLE" columnName="STATE_ABBREV"/>
</and>
</preConditions>
<update tableName="MY_TABLE">
<column name="STATE_ABBREV" value="AS"/>
<where>STATE_ABBREV IS NULL AND STATE_ID=3</where>
</update>
</changeSet>
【讨论】:
-
正如您在我的问题中的代码中看到的,这是我的假设,但我认为通过使用类似 /;或 .
-
我建议只使用 块。您可以指定您可以使用嵌套的 标记指定 块,但您仍然需要使用 ":STATE_ID=:value" 占位符指定 块然后从 中的值填写。 标签主要有助于处理不同数据库类型的布尔值差异。