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

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

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


欢迎关注公众号:慌途L
后面会慢慢将文章迁移至公众号,也是方便在没有电脑的情况下可以进行翻阅,更新的话会两边同时更新,大家不用担心!
在这里插入图片描述


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
"HINT: No function matches the given name and argument types. You might need to add explicit type casts." 这个错误提示意味着在数据库中没有与给定的函数名和参数类型匹配的函数。解决这个问题的方法是添加显式的类型转换。 一种解决方案是使用uuid_generate_v4()函数的扩展。根据引用和引用的内容,可以看出在honeydb数据库中,uuid_generate_v4()函数不存在。要解决这个问题,您需要添加uuid-ossp扩展。可以使用以下命令来添加扩展: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; 另一种解决方案是在没有扩展的情况下生成UUID。根据引用的内容,可以使用以下SQL语句生成UUID: SELECT uuid_in(md5(random()::text || clock_timestamp()::text)::cstring); 这将返回一个生成UUID。 所以,您的问题的解决方法是添加uuid-ossp扩展或使用上述SQL语句来生成UUID,并根据需要进行类型转换。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [PostgreSQL | 生成UUID 报错:HINT: No function matches the given name and argument types](https://blog.csdn.net/qq_25112523/article/details/110134090)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [在Postgres中为插入语句生成UUID?](https://blog.csdn.net/asdfgh0077/article/details/106916483)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值