【问题标题】:Copy postgres table to another schema using liquibase使用 liquibase 将 postgres 表复制到另一个模式
【发布时间】:2018-03-24 04:49:11
【问题描述】:

我想将一组表从一个模式复制到同一数据库上的另一个模式。我在 Ubuntu 上使用 postgres v9,我们使用 Liquibase 对我们的数据库进行任何更改。

我可以使用类似于下面的代码创建新表,但我需要将新表创建为select * from another table

<changeSet author="jDoe" id="1">
    <createTable tableName="abcproxy">
        <column name="errtime" type="datetime">
            <constraints primaryKey="true" nullable="false"/>
        </column>
        <column name="errmsg" type="varchar(255)">
            <constraints nullable="false"/>
        </column>
        <column name="version" type="integer">
            <constraints nullable="false"/>
        </column>
    </createTable>

我知道我们可以通过here 中提到的 sql 来做到这一点,但我想通过 Liquibase XML 配置来做到这一点。此外,如果我们可以使用 liquibase 配置复制授权/权限,那就太好了。

我可以按照here 所述尝试移动表格,但到目前为止,我的要求是复制而不是移动表格。

请让我知道实现相同目标的任何建议。谢谢。

【问题讨论】:

  • 有什么建议吗?
  • 你可以使用 select * from another table
  • 让我试试这个。谢谢!

标签: database postgresql liquibase


【解决方案1】:

您可以在changeSet 中使用sql 标签,例如:

<changeSet author="jDoe" id="1">
    <precondition onFail="MARK_RUN">
        <not>
            <tableExists tableName="abcproxy" schemaName="newSchema"/>
        </not>
    </precondition>
    <sql>create table newSchema.abcproxy as select * from oldSchema.abcproxy</sql>
</changeSet>

不过,这种方法存在一个问题:changeSet 将复制旧模式中表中的所有数据,但不会复制键。

【讨论】:

    猜你喜欢
    • 2016-11-17
    • 1970-01-01
    • 1970-01-01
    • 2021-07-29
    • 2015-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-24
    相关资源
    最近更新 更多