Re: FK constraint question - Mailing list pgsql-sql

From Steve Midgley
Subject Re: FK constraint question
Date
Msg-id CAJexoSJJ3GQ1y_CaRU+5dZ7TOa3umfsN6Kt-70WyiAbjns921A@mail.gmail.com
Whole thread Raw
In response to FK constraint question  ("Heinemann, Manfred (IMS)" <HeinemannM@imsweb.com>)
List pgsql-sql
On Wed, Apr 1, 2020 at 6:49 AM Heinemann, Manfred (IMS) <HeinemannM@imsweb.com> wrote:

Can something explain why something like the following could happen?

 

INSERT INTO task_history (task_id, user_id, task_date)

SELECT task_id, user_id, task_date

FROM task

WHERE task_id IN (1, 2, 3);

 

ERROR: insert or update on table "task_history" violates foreign key constraint "fk_task_history_task_id"

  Detail: Key (task_id)=(1) is not present in table "task".

 

Would you share the DDL create table and create FK statements? Seems weird for sure, but it would help to have the DDL to diagnose. Also, if you can provide sample data that generates this error, that will help everyone interested to reproduce your issue.

pgsql-sql by date:

Previous
From: "Heinemann, Manfred (IMS)"
Date:
Subject: FK constraint question
Next
From: Ruwan Fernando
Date:
Subject: How do CHECK Constraint Function privileges work?