postgresql 在Liquibase valueComputed中创建基表

eiee3dmh  于 5个月前  发布在  PostgreSQL
关注(0)|答案(1)|浏览(91)

我的问题如下。我有两个表,假设AB。我想合并AB表。
两个表都有以下列(主键):

  • transaction_id
  • group_id
  • leaf_id

另外,B有两列我想移到表A中:

  • representation
  • timestamp

我在Liquibase中创建了以下更改:

<update tableName="A">
            <column name="representation" valueComputed="
                (SELECT btable.representation
                FROM B btable
                WHERE btable.transaction_id = transaction_id
                AND btable.group_id = group_id
                AND btable.leaf_id = leaf_id)
            "/>
            <column name="timestamp" valueComputed="
                (SELECT btable.timestamp
                FROM B btable
                WHERE btable.transaction_id = transaction_id
                AND btable.group_idx = group_id
                AND btable.leaf_idx = leaf_id)
            "/>
</update>

字符串
所以这不起作用,因为表A没有别名,btable.transaction_id = transaction_id将被解释为btable.transaction_id = btable.transaction_id
我的问题是:有没有办法在valueComputed SQL中给base表取别名?
我知道这可以在Liquibase中使用<sql></sql>,但如果可能的话,我想避免使用原始SQL。
我用的是Postgres。
谢谢你,谢谢

4uqofj5v

4uqofj5v1#

我找不到解决方案,所以我最终在liquibase中使用了原始SQL,如下所示:

<sql>
    UPDATE A
    SET
    custom_representation = (
        SELECT btable.representation
        FROM B btable
        WHERE btable.transaction_id = transaction_id
        AND btable.group_id = group_id
        AND btable.leaf_id = leaf_id
    ),
    timestamp = (
        SELECT btable.timestamp
        FROM B btable
        WHERE btable.transaction_id = transaction_id
        AND btable.group_idx = group_id
        AND btable.leaf_idx = leaf_id
    );
</sql>

字符串

相关问题