【发布时间】:2012-09-12 09:05:14
【问题描述】:
我的问题很简单。我知道 UUID 的概念,我想生成一个来引用我数据库中“商店”中的每个“项目”。看起来很合理吧?
问题是下面一行返回错误:
honeydb=# insert into items values(
uuid_generate_v4(), 54.321, 31, 'desc 1', 31.94);
ERROR: function uuid_generate_v4() does not exist
LINE 2: uuid_generate_v4(), 54.321, 31, 'desc 1', 31.94);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
我已阅读以下页面:http://www.postgresql.org/docs/current/static/uuid-ossp.html
我在 Ubuntu 10.04 x64 上运行 Postgres 8.4。
【问题讨论】:
-
Postgres 原生支持 UUID 作为数据类型,甚至可以被索引并用作主键。但是要生成一个 UUID 值,例如为一个列建立一个默认值,你需要一个 Postgres 扩展(一个插件)。 Postgres 的许多构建(发行版)都包含这样的扩展,但不激活该扩展。请参阅correct answer by Craig Ringer 了解如何激活它。
-
如果您安装了 uuid-ossp 并且仍然收到此错误,请尝试在函数前面加上您的模式名称,例如
select dbo.uuid_generate_v4()
标签: postgresql uuid postgresql-8.4