【问题标题】:How to force Liquibase not to put the schema name into the index name?如何强制 Liquibase 不将架构名称放入索引名称中?
【发布时间】:2018-03-18 01:27:27
【问题描述】:

我有一个项目,我使用 PostgreSQL 9.5 作为 RDBMS 和 Liquibase 3.5.3 来生成数据库实体。我想使用以下 XML 在表上创建索引:

    <createIndex indexName="idx_entity_audit_event_entity_id"
        tableName="jhi_entity_audit_event">
        <column name="entity_id" type="bigint"/>
    </createIndex>

生成的SQL命令如下:

    CREATE INDEX public.idx_entity_audit_event_entity_id ON
                                            public.jhi_entity_audit_event(entity_id)

执行 Liquibase 变更集时,出现以下错误:

      Reason: liquibase.exception.DatabaseException: ERROR: syntax error at or near "."
      Position: 20 [Failed SQL: CREATE INDEX public.idx_entity_audit_event_entity_id ON public.jhi_entity_audit_event(entity_id)]

我也尝试在 pgAdmin 4 中手动执行上述脚本,但遇到了同样的错误。我试图再次手动重新创建索引,但是我从索引名称中跳过了架构名称 public 并且它起作用了。 我不确定这是否是 Liquibase 或 Postgres 问题,或者仅仅是 Liquibase 和 Postgres 版本不同步,但我无法使其正常工作。如果有人有想法,请与我和社区分享。

【问题讨论】:

    标签: xml postgresql indexing syntax-error liquibase


    【解决方案1】:

    如果您阅读了 CREATE INDEX 的 PostgreSQL 文档,您会发现以下语句:

    名字

    要创建的索引的名称。不能包含架构名称 这里;索引始终在与其父级相同的架构中创建 桌子。如果名称被省略,PostgreSQL 会选择一个合适的名称 基于父表的名称和索引列名称。

    因此,索引名称中不能包含架构名称。

    【讨论】:

      猜你喜欢
      • 2014-05-11
      • 2011-11-25
      • 2015-03-24
      • 2013-09-14
      • 1970-01-01
      • 1970-01-01
      • 2013-06-10
      • 2012-06-30
      • 1970-01-01
      相关资源
      最近更新 更多