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

Posted BingCorePower

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GreenPlum之数组合并取交集及行变列列变行函数相关的知识,希望对你有一定的参考价值。

--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.行变列函数UNNEST
select UNNEST(array[1,2,3]);

--3.列变行函数array_agg:
create temporary table temp_test01 as
select 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;

  

以上是关于GreenPlum之数组合并取交集及行变列列变行函数的主要内容,如果未能解决你的问题,请参考以下文章