0
votes

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

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 ?

INSERT INTO task VALUES ('someId', 'A');

Does Postgres prevent creating new foreign key references on tables locked by SELECT FOR UPDATE OF?

1

1 Answers

1
votes

No, it does not.

select .. for update only blocks changes (update, delete) to that row.

It does not prevent other transactions from reading that row and that's what is required to insert a row referencing the locked row.