PostgreSQL 11.1
以下过程在首次运行时正确运行。但是,在第二次运行时,它会出现以下错误:
错误:查询没有结果数据的目标提示:如果要 放弃SELECT的结果,请改用PERFORM。内容: PL / pgSQL函数merge_charts()第19行位于SQL语句SQL状态: 42601
该如何解决?
CREATE OR REPLACE PROCEDURE merge_charts()
LANGUAGE plpgsql
AS $$
DECLARE
current_table VARCHAR(50);
BEGIN
BEGIN
current_table :='charts';
RAISE NOTICE 'Moving data to %', current_table ;
insert into phoenix.charts (recid, groupid, chart_number, timestamp, modified, donotsee, selfpay, cashonly)
select n.recid, n.groupid, n.chart_number, n.timestamp, n.modified, n.donotsee, n.selfpay, n.cashonly
from nova.charts n
where
n.recid not in (select recid from phoenix.charts);
SELECT setval('phoenix.charts_recid_seq', max(recid)) FROM nova.charts;
EXCEPTION
WHEN unique_violation THEN
RAISE NOTICE 'ERROR: Rolling Back; Unique_violation error in table: %', current_table ;
ROLLBACK;
END;
END;
$$;
CALL merge_charts();