gpt4 book ai didi

xml - liquibase数据库重构xml createIndex

转载 作者:行者123 更新时间:2023-11-29 13:29:18 25 4
gpt4 key购买 nike

回答这个问题:Postgres table constraint using group-by ,我正在尝试将以下 Postgres 代码翻译成 liquibase XML

create unique index idx_table on table(subcategory, base_unit)
where base_unit;

我试过这个:

<createIndex indexName="idx_table"
tableName="table"
unique="true">
<columnNames="subcategory, base_unit"/>
<where>base_unit</where>
</createIndex>

但这给了我错误: 元素类型“columnNames”必须后跟属性规范“>”或“/>”。

更新:

<createIndex indexName="idx_table"
tableName="table"
unique="true">
<column name="subcategory"/>
<column name="base_unit"/>
<where>base_unit</where>
</createIndex>

导致错误:

Invalid content was found starting with element 'where'. One of '{"liquibase.org/xml/ns/dbchangelog":column}' is expected.

最佳答案

Liquibase 目前不支持 createIndex 中的“where”部分。

您将需要使用 modifySql:

<changeSet id="YOUR_ID" author="YOU">
<createIndex indexName="idx_table"
tableName="table"
unique="true">
<column name="subcategory"/>
<column name="base_unit"/>
</createIndex>
<modifySql>
<append value=" where base_unit"/>
</modifySql>
</changeSet>

或者直接使用sql:

<changeSet id="YOUR_ID" author="YOU">
<sql>create unique index idx_table on table(subcategory, base_unit) where base_unit</sql>
</changeSet>

关于xml - liquibase数据库重构xml createIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27493753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com