我正在使用信息模式进行嵌套游标,以节省我在所有表上插入的时间。
我收到错误 [42P01]错误:关系“rec2”不存在 其中:PL / pgSQL函数test()在SQL语句第22行
请帮我解决此问题。
以下是代码,非常感谢任何帮助。
提前感谢。
CREATE OR REPLACE FUNCTION test()
RETURNS VOID AS
$$
DECLARE
rec1 RECORD;
rec2 RECORD;
BEGIN
FOR rec1 IN
SELECT
C.table_name,
C.column_name
FROM "information_schema"."columns" AS C
WHERE C.table_schema = 'prod1'
AND C.table_name LIKE 'prd_tbl%'
AND C.column_name <> 'id'
ORDER BY C.table_name ASC
LOOP
FOR rec2 IN
SELECT table_name
FROM "information_schema"."tables"
WHERE table_schema = 'ec2'
ORDER BY table_name ASC
LOOP
SELECT rec2.*
FROM rec2
EXCEPT
SELECT rec1.column_name.*
FROM rec1;
END LOOP;
END LOOP;
END;
$$
LANGUAGE plpgsql STABLE;