OushuDB多语言UDF
1、python 编写 UDF
psql -d postgres
CREATE LANGUAGE plpythonu;
create or replace function hello()
returns text
as $$
import os
return os.path.abspath('.')
$$ language plpythonu;
执行
select hello();
2、C 语言编写 UDF
c 代码
#include "postgres.h"
#include "fmgr.h"
PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(add_ab);
Datum
add_ab(PG_FUNCTION_ARGS)
{
int32 arg_a = PG_GETARG_INT32(0);
int32 arg_b = PG_GETARG_INT32(1);
PG_RETURN_INT32(arg_a + arg_b);
}
编译
gcc -I/usr/local/oushudb-4.7.0.0/include/postgresql/server -fPIC -c cfunc.c
gcc -shared -o cfunc.so cfunc.o
建函数
psql -d postgres
CREATE FUNCTION add(int,int) RETURNS integer AS '/home/gpadmin/cfunc','add_ab' LANGUAGE C STRICT;
执行
select add(1,2);
3、Java 编写 UDF
psql -d postgres
create language pljava;
CREATE FUNCTION getsysprop_udf(VARCHAR)
RETURNS VARCHAR
AS 'java.lang.System.getProperty'
LANGUAGE pljava;
执行
Select getsysprop_udf('user.home');