Liquibase 插入 select 多行 postgres

Liquibase insert select multiple rows postgres

我想将 table2 中的多行插入到 table1 中。问题是我想计算 table1 中的一些字段,以及我想从 table2 select 计算的一些行。例如这样的事情:

insert into table1 (id, selectField1, selectField2, constant)
values ((gen_random_uuid()), (select superField1 from table2), (select superField2 from table2), 'test');

所以逻辑是 select superField1superField2 来自 table2 中的所有行,然后将它们插入到 table1 中,具有常量值 test 并生成 uid。在 table1 中插入时,superField1superField2 应该来自 table2 中的同一行。我怎样才能使用 liquibase 实现这样的目标?

P.S:我正在使用 <sql> 标记,因为使用 SQL 比使用 XML 变更集更容易实现,但是如果您知道如何在XML 也将不胜感激,但仅在 SQL 中也足够了。数据库管理系统是 postgres.

如果源是 SELECT 语句,请不要使用 VALUES 子句:

insert into table1 (id, selectField1, selectField2, constant)
select gen_random_uuid(), superField1, superField2, 'test'
from table2;