1、定义数据拼接函数
CREATE OR REPLACE FUNCTION "public"."sfun"("results" _numeric, "val" numeric) RETURNS "pg_catalog"."_numeric" AS $BODY$ BEGIN results :=array_append(results,val::numeric); RETURN results; END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100; ALTER FUNCTION "public"."sfun"("results" _numeric, "val" numeric) OWNER TO "postgres";
2、定义数据处理函数
CREATE OR REPLACE FUNCTION "public"."sffun_o3_8h"("results" _numeric) RETURNS "pg_catalog"."numeric" AS $BODY$ DECLARE tmp integer; len integer; ret numeric[];--结果 BEGIN len=array_length(results , 1); if len<8 then return -999; end if; for i in 8..len loop tmp=0; for j in 0..7 loop tmp=tmp+results[i-j]; end loop; tmp=tmp/8::numeric; ret:=array_append(ret,tmp::numeric); end loop; ret=array_sort(ret,'asc'); RETURN ret[array_length(ret,1)]; END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100; ALTER FUNCTION "public"."sffun_o3_8h"("results" _numeric) OWNER TO "postgres";
3、定义臭氧8小时触发器
CREATE AGGREGATE agg_o3_8h( BASETYPE = numeric, SFUNC = sfun, STYPE = numeric[], FINALFUNC = sffun_o3_8h );
转载于:https://www.cnblogs.com/tiandi/p/11165678.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。