您当前的位置: 首页 >  慌途L ar

PostgreSQL | 生成UUID 报错:HINT: No function matches the given name and argument types

慌途L 发布时间:2020-11-25 18:16:09 ,浏览量:3

在PG数据库上新建表结构:

CREATE TABLE "public"."t_test" (
  "guid" uuid NOT NULL DEFAULT uuid_generate_v4(),
  "data" jsonb,
  "create_time" timestamptz(6) DEFAULT now(),
  CONSTRAINT "test_pkey" PRIMARY KEY ("guid")
);

报错:

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";

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

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";

执行语句时可能会出现权限问题,扩展需要切换到权限高的账号创建。

关注
打赏
1688896170
查看更多评论

慌途L

暂无认证

  • 3浏览

    0关注

    118博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0471s