使用 liquibase 将 postgres table 复制到另一个模式

Copy postgres table to another schema using liquibase

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

我可以使用类似于下面的代码创建新的 table,但我需要将新的 table 创建为 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 配置复制 grants/privileges,那就太好了。

我可以尝试移动 table 所提到的 here 但截至目前,我的要求是 复制 而不是 移动 tables.

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

您可以在 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 将复制旧架构中 table 中的所有数据,但不会复制键。