0
我正在寫一個函數來創建多個CSV文件。PostgreSQL函數生成csv文件
DECLARE r RECORD;
DECLARE ra RECORD;
DECLARE ro RECORD;
BEGIN
DROP TABLE IF EXISTS tab1;
DROP TABLE IF EXISTS tab2;
DROP TABLE IF EXISTS tab3;
EXECUTE 'CREATE TABLE tab1 AS SELECT DISTINCT num FROM analysis';
FOR r IN EXECUTE 'SELECT num AS num FROM tab1'
LOOP
EXECUTE 'CREATE TABLE tab2 AS SELECT id FROM analysis WHERE num_vista = r.num';
FOR ra IN SELECT id FROM tab2
LOOP
EXECUTE 'CREATE TABLE tab3 AS SELECT DISTINCT oid FROM area WHERE analysis_id = ra.id';
FOR ro IN SELECT oid FROM tab3
LOOP
EXECUTE 'COPY
(
SELECT created_at, result, updated_at FROM area
WHERE oid = ro.oid
) TO "C:/Program Files/PostgreSQL/9.5/data/Num$rOid$ro.csv" WITH CSV HEADER;';
END LOOP;
END LOOP;
END LOOP;
END;
但我有此錯誤: 元素從表r爲缺少
LINE 1: ...tab2 AS SELECT id FROM analysiy WHERE num_vista = r.num
你知不知道我該怎麼辦? 在此先感謝!
提供完整的sql請 –