运行此 SQL 时出现 function get_random_uuid() does not exist
错误:
ALTER TABLE "posts"ALTER COLUMN "id"SET DEFAULT gen_random_uuid()
我可以看到此查询中列出的 pgcrypto
模块 select * from pg_available_extensions;
。我在 Ubuntu 14.04 上使用 PostgreSQL 9.4.5。
我错过了什么吗?
最佳答案
您需要在当前数据库/模式中加载 pgcrypto 扩展
CREATE EXTENSION pgcrypto;
像这样(使用 PostgreSQL 12 测试):
# SELECT gen_random_uuid();
ERROR: function gen_random_uuid() does not exist
LINE 1: select gen_random_uuid();
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
# CREATE EXTENSION pgcrypto;
CREATE EXTENSION
# SELECT gen_random_uuid();
gen_random_uuid
--------------------------------------
19a12b49-a57a-4f1e-8e66-152be08e6165
(1 row)
关于PostgreSQL 函数 gen_random_uuid() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35959265/