【发布时间】:2025-12-28 08:25:17
【问题描述】:
我定义了一个函数如下
CREATE OR REPLACE FUNCTION processActivityCommentTable() RETURNS INTEGER AS $$
DECLARE
activityCommentRow RECORD;
i RECORD;
activityId integer;
attachments text;
attachmentId integer;
cur1 CURSOR FOR SELECT ac.id, ac.attachments from activitycomment ac where ac.attachments is not null;
BEGIN
OPEN cur1;
FOR activityCommentRow in cur1
LOOP
RAISE NOTICE 'currently processing for %s ...', activityCommentRow.id;
-- can do some processing here
activityId = activityCommentRow.id;
attachments = activityCommentRow.attachments;
SELECT foo FROM regexp_split_to_table(attachments,E'{"id":') as foo;
FOR i in select * from foo
LOOP
select regexp_replace(i,'(,"name").*','') into attachmentId;
EXECUTE 'INSERT INTO attachment (activity_comment_id) values(' || attachmentId ||') where id= ' activityId;
END LOOP;
END LOOP;
CLOSE cur1;
END;
$$ LANGUAGE plpgsql;
在执行时
select processActivityCommentTable();
它给了我以下错误
错误:光标“cur1”已在使用中 SQL 状态:42P03 上下文:PL/pgSQL 函数 processactivitycommenttable() 第 12 行 FOR 光标上方
有人可以帮忙吗?
【问题讨论】:
标签: postgresql postgresql-9.1 plpgsql