Postgresql 生成UUID

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 the gen_random_uuid() function from the pgcrypto module 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)

>

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

转载于:https://my.oschina.net/beetlerx/blog/1553328

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值