执行此功能时出现此错误: “无法打开与OID 327969的关系” 该函数在Postgres 10.6中正常工作,但在Postgres 12.4中抛出此错误 任何帮助深表感谢。预先感谢。
功能:
CREATE OR REPLACE FUNCTION Fn_Drop_Views()
RETURNS integer
LANGUAGE plpgsql
AS $function$
DECLARE
l_schema varchar(100);
cur_tab CURSOR FOR
select *
from information_schema.views
where table_schema = l_schema
order by table_name;
cur_tab_rec RECORD;
v_sql varchar(4000);
v_count integer := 0;
BEGIN
l_schema := current_schema();
--RAISE NOTICE 'l_schema: %', l_schema;
FOR cur_tab_rec IN cur_tab
LOOP --1
v_sql := 'DROP VIEW IF EXISTS ' || l_schema || '.' || cur_tab_rec.table_name || ' CASCADE';
v_count := v_count + 1;
--RAISE NOTICE 'view_name: %', v_count || '. ' || cur_tab_rec.table_name;
--RAISE NOTICE 'v_sql: %', v_count || '. ' || v_sql;
EXECUTE v_sql;
END LOOP;--1
RETURN 1;
EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'OTHERS ERROR: >>> %', SQLERRM;
RETURN 0;
END;
$function$
;