【问题标题】:Hibernate _AUD Table - FOR statement from SELECTHibernate _AUD 表 - 来自 SELECT 的 FOR 语句
【发布时间】:2016-06-20 10:59:27
【问题描述】:

我必须使用 Liquibase 和 Postgres 手动更新休眠 _aud 表。

我将解释我的算法:

FIRST : 从 person_AUD 表中选择所有不同的 id

select distinct id from product_aud;

第二个:根据“id list”将新记录插入product_aud。

所以我想做这样的事情:

MY_IDs = select distinct id from product_aud; //My row list with id column
    for(int i=1;i <MY_IDs;i++ ) {
           INSERT INTO product_aud(id,rev,revtype,revend)
            VALUES (i, nextval ('hibernate_sequence'), 1, null)

    }

我怎样才能只使用 SQL 来做到这一点?

【问题讨论】:

    标签: hibernate postgresql liquibase


    【解决方案1】:

    你可以这样做:

    insert into product_aud(id,rev,revtype,revend)
    select persons.id, nextval ('hibernate_sequence'), 1, null
    from (
        select distinct id from person_aud
    ) persons;
    

    【讨论】:

    • 好的,谢谢...如何使用函数和光标获得相同的结果?
    • 不太清楚你所说的“函数和游标”是什么意思。你可以把这个插入语句放到一个sql文件中,然后用liquibase的sql更改集调用它。
    猜你喜欢
    • 2012-06-14
    • 1970-01-01
    • 2011-10-03
    • 2011-03-12
    • 1970-01-01
    • 2016-10-30
    • 2021-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多