postgresql – 在Postgres中为Insert语句生成UUID?
发布时间:2020-12-13 16:55:30 所属栏目:百科 来源:网络整理
导读:我的问题很简单。我知道一个UUID的概念,我想生成一个引用每个’项目’从’存储’在我的数据库。似乎合理吗? 问题是下面的行返回一个错误: honeydb=# insert into items values(uuid_generate_v4(),54.321,31,'desc 1',31.94);ERROR: function uuid_genera
我的问题很简单。我知道一个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(),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。
uuid是一个contrib模块,因此默认情况下不会加载到服务器中。您必须将其加载到数据库中才能使用它。
对于现代PostgreSQL版本(9.1和更新版本)很容易: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; 但对于9.0及以下版本,您必须改为运行SQL脚本以加载扩展。见the documentation for contrib modules in 8.4。 对于Pg 9.1和更高版本,而是读取the current contrib docs和 如果您使用PostgreSQL的打包版本,您可能需要安装一个包含contrib模块和扩展的单独的包。在包管理器数据库中搜索’postgres’和’contrib’。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |