无法在Redshift存储过程中动态截断表

问题描述 投票:0回答:1

我在Redshift中有一个表(我们称它为状态表),在其中设置了要截断的表的状态。为此,我创建了Redshift Stored Procedure。这是我的SP代码:

CREATE OR REPLACE PROCEDURE padb.truncate_table()
AS $$
DECLARE
    v_tpsl RECORD;
    exec_statement VARCHAR(256);
BEGIN
    FOR v_tpsl in SELECT * from padb.tablename_process_status_log WHERE status = 'TRUE' LOOP
    exec_statement = 'TRUNCATE TABLE padb.' + quote_ident(v_tpsl.staging_table_name) + '_test;';
    RAISE INFO 'statement = %', exec_statement;
    --EXECUTE 'TRUNCATE TABLE padb.padb_fraud_verified_stage_latest_test';
    EXECUTE exec_statement;
  END LOOP;
END;
$$
LANGUAGE plpgsql;

SQL语句SELECT * from padb.tablename_process_status_log WHERE status = 'TRUE'的输出是这个:

enter image description here

以及我要截断的表也存在:

enter image description here

现在,当我正在调用存储过程时,出现此错误:SQL Error [500310] [34000]: [Amazon](500310) Invalid operation: cursor does not exist;

enter image description here

我查看了SP的文档,以检查是否可以进行截断。通过查看examples,看起来是可能的。

我不确定这是怎么回事。我正在使用RedshiftJDBC42-no-awssdk-1.2.34.1058.jar并通过DBeaver连接。

amazon-redshift
1个回答
0
投票

看来我找到了答案。根据thisAny cursor that is open (explicitly or implicitly) is closed automatically when a COMMIT, ROLLBACK, or TRUNCATE statement is processed。在循环的下一个迭代中,它试图访问已关闭的游标。

© www.soinside.com 2019 - 2024. All rights reserved.