greenplum扩展UUID函数

greenplum的uuid函数

step1:为数据库添加python支持

先保证$GPHOME/ext/中包含python文件夹,否则无法增加python扩展

[root@sit-greenplum01 local]# cd greenplum-db-6.20.5/
[root@sit-greenplum01 greenplum-db-6.20.5]# cd ext/
[root@sit-greenplum01 ext]# ls -l
total 0
drwxr-xr-x 6 gpadmin gpadmin 56 Oct 17  2022 python
[root@sit-greenplum01 ext]# cd python/
[root@sit-greenplum01 python]# ll

执行扩展命令

执行扩展命令(注意是在shell中执行,不是进入gp的命令行)

createlang plpythonu -d tz_datawarehouse_test

1、使用python创建uuid函数

CREATE OR REPLACE FUNCTION "public"."uuid_python"()
  RETURNS "pg_catalog"."varchar" AS $BODY$
import uuid
return uuid.uuid1()
$BODY$
  LANGUAGE 'plpythonu' VOLATILE COST 100
;
ALTER FUNCTION "public"."uuid_python"() OWNER TO "gpadmin";

2、调用uuid函数

CREATE OR REPLACE FUNCTION "public"."get_uuid"()
  RETURNS "pg_catalog"."text" AS $BODY$BEGIN
return md5(uuid_python());
END
$BODY$
  LANGUAGE 'plpgsql' VOLATILE COST 100
;
ALTER FUNCTION "public"."get_uuid"() OWNER TO "gpadmin";
posted @ 2025-06-26 17:07  数据库小白(专注)  阅读(36)  评论(0)    收藏  举报