PostgreSQL 有扩展名 'uuid-ossp' 但找不到 uuid_generate_v4()

问题描述 投票:0回答:2

我安装了 PostgreSql 并检查扩展名“uuid-ossp”是否存在。

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

我用sql查询检查了结果。

SELECT * FROM pg_available_extensions;

enter image description here

但是创建表时不能使用uuid_generate_v4()函数。

CREATE TABLE my_table
(
  uuid UUID NOT NULL UNIQUE DEFAULT uuid_generate_v4()
);

错误信息如下

SQL Error [42883]: ERROR: function uuid_generate_v4() does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.

我正在寻找解决这个问题的方法。我确认超级用户是可执行的。如何让我创建的用户能够运行它?

postgresql uuid
2个回答
0
投票

也许架构不正确。您是否尝试过:

CREATE TABLE public.my_table (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,

0
投票

使用户成为超级用户并重新连接后,就可以使用uuid_generate_v4()函数了。

After making the user a superuser and reconnecting, the uuid_generate_v4() function can be used.

有什么方法可以在不使其成为超级用户的情况下使用它吗?

© www.soinside.com 2019 - 2024. All rights reserved.