[Err] ERROR: wrong record type supplied in RETURN NEXT
在写GP 输出不定长列数据表 函数时,报了一个错,百思不得其解。在公司大佬帮助下,知道是什么鬼了。。
先看看例子吧:
---- 函数定义
CREATE OR REPLACE FUNCTION "vt_profile"."udf_statistics_show_data"(sql_ text) RETURNS SETOF "pg_catalog"."record" AS $BODY$ declare sql_ alias for $1; r RECORD; begin
FOR r IN EXECUTE sql_ LOOP RETURN NEXT r; END LOOP; return; end $BODY$ LANGUAGE plpgsql IMMUTABLE COST 1000 ROWS 1000 ; ALTER FUNCTION "vt_profile"."udf_statistics_show_data"(sql_ text) OWNER TO "etl_role";
---- 函数调用(会报错)
select * from vt_profile.udf_statistics_show_data('select ''a'' appname,''a'' label,123 as w201845 ,123 as w201911,123 as w201912') as (appname varchar(100),label varchar(100),w201845 numeric,w201911 numeric,w201912 numeric);
---- 正确调用
select * from vt_profile.udf_statistics_show_data('select ''a''::varchar appname,''a''::varchar label,123::numeric as w201845 ,123::numeric as w201911,123::numeric as w201912') as (appname varchar(100),label varchar(100),w201845 numeric,w201911 numeric,w201912 numeric);
知道了正确的调用,再看看错误提醒,原来是告诉我们,输出的数据类型 与定义的类型不一致!
来自:http://www.cnblogs.com/jackicalsong
爬虫与转载请注明出处~