gpt4 book ai didi

sql - postgreSQL uuid 生成

转载 作者:太空狗 更新时间:2023-10-30 01:43:05 25 4
gpt4 key购买 nike

select uuid_generate_v4() as one, uuid_generate_v4() as two;

“一个”uuid和“两个”uuid是相等的!

CREATE TABLE "TB"
(
"Id" uuid NOT NULL DEFAULT uuid_generate_v4(),
"Title" character varying NOT NULL,
CONSTRAINT "TB_Class_ID" PRIMARY KEY ("Id")
);

postgresql 9.0 pgAdmin 1.12.3

insert into "TB" ("Id", "Title") values (uuid_generate_v4(), '111');
insert into "TB" ("Id", "Title") values (uuid_generate_v4(), '111');
insert into "TB" ("Id", "Title") values (uuid_generate_v4(), '111');

insert into "TB" ("Title") values ('111');
insert into "TB" ("Title") values ('111');
insert into "TB" ("Title") values ('111');

结果:

ERROR:  duplicate key value violates unique constraint "TB_Class_ID"
DETAIL: Key ("Id")=(12ab6634-995a-4688-9a9a-ee8c3fe24395) already exists.

鉴于

postgreSQL 大师 9.2.0.4

insert into "TB" ("Id", "Title") values (uuid_generate_v4(), '111');
insert into "TB" ("Id", "Title") values (uuid_generate_v4(), '111');
insert into "TB" ("Id", "Title") values (uuid_generate_v4(), '111');

结果:1​​ 行受影响;

我理解maestro是一条一条添加记录的,但是为什么uuid_generate_v4()调用两次后返回的值相同? (在 pgAdmin 案例中)。

如何通过一个请求添加多行?

最佳答案

在过去的某个时候,uuid_generate_* 函数被错误地标记为 IMMUTABLE,这将导致您显示的行为。这已在所有最新的次要版本中得到修复,但您必须重新运行安装脚本 (uuid-ossp.sql) 以获取更新的函数定义。 (您还可以查看安装脚本以验证您是否拥有最新版本。函数应标记为 VOLATILE。)

关于sql - postgreSQL uuid 生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6939628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com