[英]Does postgres “SELECT FOR UPDATE” restrict to create new foreign key references ?
There are two tables, one is referenced by another with foreign key constraint. 有两个表,其中一个被外键约束引用。
CREATE TABLE record
(
id UUID PRIMARY KEY NOT NULL
);
CREATE TABLE task
(
id UUID PRIMARY KEY NOT NULL,
record_id UUID,
CONSTRAINT fk_task_record_id FOREIGN KEY (record_id)
REFERENCES record (id)
);
The question is : if lock on record
row is aquired by 问题是:如果对
record
行的锁定是由
SELECT * FROM record where id = 'A' FOR UPDATE OF record
Could I create new foreign key in task
table and reference this very record
row ? 我可以在
task
表中创建新的外键并引用此record
行吗?
INSERT INTO task VALUES ('someId', 'A');
Does Postgres prevent creating new foreign key references on tables locked by SELECT FOR UPDATE OF
? Postgres是否阻止在
SELECT FOR UPDATE OF
锁定的表上创建新的外键引用?
No, it does not. 不,不是的。
select .. for update
only blocks changes (update, delete) to that row. select .. for update
仅阻止对该行的更改 (更新,删除)。
It does not prevent other transactions from reading that row and that's what is required to insert a row referencing the locked row. 它不会阻止其他事务读取该行,而这就是插入引用锁定行的行所需要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.