greenplum数据库python自定义函数

greenplum数据库(下面简称gp数据库)支持自定义函数,下面介绍的是python编写的自定义简单函数。聚类函数较复杂,自我感觉不适合在gp数据库中编写。


python自定义函数说明了只要python能对行级数据做的处理,gp都能做。

样例:python对json做处理返回多行。

create or replace function public.json_parse(data text) returns setof text

AS $$

   import json

   try:

       mydata=json.loads(data)

   except:

      return ['parse error']

   returndata=[]

   try:

      for people in mydata['a']:

    returndata.append(people['b'])

   except:

      return ['223']

   return returndata

$$ LANGUAGE plpythonu;