使用FOREACH插入POSTGRESQL

使用FOREACH插入POSTGRESQL,sql,postgresql,Sql,Postgresql,我有以下功能: do $$ declare cd_id bigint; config_detail_ids bigint[]; partner_script varchar := 'partner_create_cancel_option.groovy'; begin select array (select id from config_detail where code = 'partner') into con

我有以下功能:

do
$$
    declare
        cd_id bigint;
        config_detail_ids bigint[];
        partner_script varchar := 'partner_create_cancel_option.groovy';
    begin
        select array (select id from config_detail where code = 'partner') into config_detail_ids;

        update config_detail set create_flag = true, create_script = partner_script,
        cancel_flag = false, cancel_script = partner_script, renew_flag = false, renew_script = null,
        change_status_flag = false, change_status_script = partner_script, label = null,
        deeplink = null, deduplication_flag = true
        where id in (config_detail_ids);

        foreach cd_id in array config_detail_ids loop
            insert into change_status_transition (old_status, new_status, config_detail_id) values
            ('WAIT_CANCEL', 'CANCEL', cd_id),
            ('WAIT_CANCEL', 'FAIL', cd_id),
            ('PROCESSING', 'FAIL', cd_id);
        end loop;
    end;
$$ language plpgsql;
我不明白我遇到的错误是什么问题:

ERROR: operator does not exist: bigint = bigint[]
No operator matches the given name and argument types. You might need to add explicit type casts.
PL/pgSQL function inline_code_block line 9 at SQL statement

这是我的
foreach
循环的问题吗?如何解决此问题?

错误必须来自

update config_detail set ...
where id in (config_detail_ids);
这将比较
id
config\u detail\u id
,导致显示错误

如果要与数组的元素进行比较,请使用
=ANY

... WHERE id = ANY (config_detail_ids)

错误一定来自于

update config_detail set ...
where id in (config_detail_ids);
这将比较
id
config\u detail\u id
,导致显示错误

如果要与数组的元素进行比较,请使用
=ANY

... WHERE id = ANY (config_detail_ids)

不需要循环,使用UNNEST()来取消数组的嵌套,并使用侧向来生成值:

INSERT INTO change_status_transition (old_status, new_status, config_detail_id)
SELECT  *
FROM    UNNEST( ARRAY[1,2,3]) input(cd_id) -- use your array as input
    ,   LATERAL(VALUES
                ('WAIT_CANCEL', 'CANCEL', cd_id),
        ('WAIT_CANCEL', 'FAIL', cd_id),
        ('PROCESSING', 'FAIL', cd_id)
)   v(old_status, new_status, config_detail_id)

不需要循环,使用UNNEST()来取消数组的嵌套,并使用侧向来生成值:

INSERT INTO change_status_transition (old_status, new_status, config_detail_id)
SELECT  *
FROM    UNNEST( ARRAY[1,2,3]) input(cd_id) -- use your array as input
    ,   LATERAL(VALUES
                ('WAIT_CANCEL', 'CANCEL', cd_id),
        ('WAIT_CANCEL', 'FAIL', cd_id),
        ('PROCESSING', 'FAIL', cd_id)
)   v(old_status, new_status, config_detail_id)