GreenPlum之数组合并取交集及行变列、列变行函数

来源:互联网 发布:凡科建站怎么监测数据 编辑:程序博客网 时间:2024/06/07 02:25
--1.利用INTERSECT关键字数组之间交集函数CREATE OR REPLACE FUNCTION array_intersect(anyarray, anyarray)  RETURNS anyarray  AS $$     SELECT ARRAY(        SELECT UNNEST($1)        INTERSECT        SELECT UNNEST($2));$$ LANGUAGE SQL;select array_intersect(array[1,2,3],array[2,3,4]);--2.行变列函数UNNESTselect UNNEST(array[1,2,3]);--3.列变行函数array_agg:create temporary table temp_test01 asselect array_agg(c) aggtest from (values(NULL),('1'),('2'),('3'))tb(c);select UNNEST(aggtest) from temp_test01;select array_agg((id)) from (select id,md5(random()::text),clock_timestamp() from generate_series(1,100) t(id)) t1;


原创粉丝点击