加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Postgresql 生成UUID

发布时间:2020-12-13 16:46:52 所属栏目:百科 来源:网络整理
导读:postgresql 生成uuid select uuid_generate_v4(); uuid_generate_v4-------------------------------------- 6088c013-a45d-4b68-b70f-2b290388160d(1 row) 如果提示 ERROR: function uuid_generate_v4() does not existLINE 1: select uuid_generate_v4();

postgresql 生成uuid

> select uuid_generate_v4();
           uuid_generate_v4
--------------------------------------
 6088c013-a45d-4b68-b70f-2b290388160d
(1 row)

如果提示

ERROR:  function uuid_generate_v4() does not exist
LINE 1: select uuid_generate_v4();
               ^
HINT:  No function matches the given name and argument types. 
You might need to add explicit type casts.

说明需要创建uuid-ossp 扩展,执行命令

> create extension "uuid-ossp";
CREATE EXTENSION

这一步可能提示没有权限,那么需要更高权限的账号。

postgresql 官方文档说,如果只是使用随机的uuid,建议使用pgcrypto扩展的gen_random_uuid()替代:

Note:If you only need randomly-generated (version 4) UUIDs,consider using thegen_random_uuid()function from thepgcryptomodule instead.

-- https://www.postgresql.org/docs/current/static/uuid-ossp.html

同样,创建扩展,然后使用命令

> create extension "pgcrypto";
CREATE EXTENSION
> select gen_random_uuid();
           gen_random_uuid            
--------------------------------------
 f7d44f9a-3118-40b4-bde5-3dc964f78994
(1 row)

>

可能会有权限问题,扩展需要切换到权限高的账号创建。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读