PostgreSQL 函数 gen_random_uuid() 不工作

标签 postgresql ubuntu-14.04

运行此 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/

相关文章:

c - 意外标记附近的语法错误

postgresql - 创建物化 View 时如何指示列不可为空?

json - 如何在 Go 中进行嵌套的 JSON 响应?

postgresql - 使用 LIMIT 的慢 Postgres 查询

postgresql - 如何让 date_part 查询命中索引?

neo4j - 在 ubuntu 14.04 上安装 neo4j 失败

linux - 尝试在 VM 上安装 OpenCL

java - 哪个更好 - 抛出异常或事先检查错误

python - 如何在 linux-64 上为 Anaconda Python 3.5 安装图形工具?

linux - 如何将 id_rsa.pub 转换为 id_rsa?