Greenplum扩展-uuid-ossp实现uuid功能

 背景:

数据从postgres迁移到greenplum,源端使用存储过程中使用到uuid扩展,但是greenplum6中不支持存储过程,且默认安装没有uuid扩展

--创建函数报错
CREATE OR REPLACE FUNCTION "iitank_wrng_final"."uuid_generate_v1"()
  RETURNS "pg_catalog"."uuid" AS '$libdir/uuid-ossp', 'uuid_generate_v1'
  LANGUAGE c VOLATILE STRICT
  COST 1;



-------------------------------------------------------------
Query:
CREATE OR REPLACE FUNCTION "iitank_wrng_final"."uuid_generate_v1"()
  RETURNS "pg_catalog"."uuid" AS '$libdir/uuid-ossp', 'uuid_generate_v1'
  LANGUAGE c VOLATILE STRICT
  COST 1
Result: ERROR:  could not access file "$libdir/uuid-ossp": No such file or directory


-------------------------------------------------------------
--End--

解决

尝试增加 uuid扩展:

CREATE EXTENSION "uuid-ossp";

--报错
ERROR:  could not access file "$libdir/uuid-ossp": No such file or directory
--查看路径
[gpadmin@gsgp60 contrib]$ pg_config --pkglibdir
/usr/local/greenplum-db-6.19.1/lib/postgresql

该路径下无uuid-ossp.os文件

尝试过从pg直接复制到路径报错

正常增加扩展的过程为:

  • 下载源码到master节点,编译安装到指定目录
  • 在数据库中通过[create extension xxx;]创建扩展

网上没有找到uuid-ossp扩展

故尝试以下方法-使用python中uuid

--进入路径确定存在python
[gpadmin@gsgp60 local]$ cd /usr/local/greenplum-db-6.19.1/ext
[gpadmin@gsgp60 ext]$ ls
python

--createlang plpythonu -d databasename
[gpadmin@gsgp60 ext]$ createlang plpythonu -d test  --指定数据库

创建函数

create or replace function uuid_python1() returns varchar(32)
AS $$
  import uuid
  return uuid.uuid1()
$$ LANGUAGE plpythonu;

--测试
select uuid_python1();
--返回结果
uuid_python1
2fb74df4-1991-11ee-85ee-d4ae52b43ff7

扩展相关资源:

猜你喜欢

转载自blog.csdn.net/wangning0714/article/details/131050413