agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
FK constraint question
4+ messages / 4 participants
[nested] [flat]

* FK constraint question
@ 2020-04-01 13:49 Heinemann, Manfred (IMS) <HeinemannM@imsweb.com>
  2020-04-01 15:29 ` Re: FK constraint question Steve Midgley <science@misuse.org>
  2020-04-22 15:50 ` Re: FK constraint question Samed YILDIRIM <samed@reddoc.net>
  2020-04-22 16:31 ` Re: FK constraint question Ashutosh Sharma <ashu.coek88@gmail.com>
  0 siblings, 3 replies; 4+ messages in thread

From: Heinemann, Manfred (IMS) @ 2020-04-01 13:49 UTC (permalink / raw)
  To: pgsql-sql@lists.postgresql.org <pgsql-sql@lists.postgresql.org>

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".

Thanks,
Manfred

________________________________

Information in this e-mail may be confidential. It is intended only for the addressee(s) identified above. If you are not the addressee(s), or an employee or agent of the addressee(s), please note that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this e-mail in error, please notify the sender of the error.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: FK constraint question
  2020-04-01 13:49 FK constraint question Heinemann, Manfred (IMS) <HeinemannM@imsweb.com>
@ 2020-04-01 15:29 ` Steve Midgley <science@misuse.org>
  2 siblings, 0 replies; 4+ messages in thread

From: Steve Midgley @ 2020-04-01 15:29 UTC (permalink / raw)
  To: Heinemann, Manfred (IMS) <HeinemannM@imsweb.com>; +Cc: pgsql-sql@lists.postgresql.org <pgsql-sql@lists.postgresql.org>

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.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: FK constraint question
  2020-04-01 13:49 FK constraint question Heinemann, Manfred (IMS) <HeinemannM@imsweb.com>
@ 2020-04-22 15:50 ` Samed YILDIRIM <samed@reddoc.net>
  2 siblings, 0 replies; 4+ messages in thread

From: Samed YILDIRIM @ 2020-04-22 15:50 UTC (permalink / raw)
  To: Heinemann, Manfred (IMS) <heinemannm@imsweb.com>; pgsql-sql@lists.postgresql.org <pgsql-sql@lists.postgresql.org>

<div>Hello Manfred,</div><div> </div><div>Did the table named <em>task</em> have child tables? The records whose task_id was 1 were in child tables rather than <em>task?</em></div><div> </div><div>Could you please try following query?</div><div> </div><div><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in">INSERT INTO task_history (task_id, user_id, task_date)</p><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in">SELECT task_id, user_id, task_date</p><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in">FROM <em><strong>only</strong></em> task</p><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in">WHERE task_id IN (1, 2, 3);</p></div><div>Best regards.</div><div>Samed YILDIRIM</div><div> </div><div> </div><div> </div><div>01.04.2020, 16:49, "Heinemann, Manfred (IMS)" &lt;heinemannm@imsweb.com&gt;:</div><blockquote><div lang="EN-US"><div><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in">Can something explain why something like the following could happen?</p><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in"> </p><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in">INSERT INTO task_history (task_id, user_id, task_date)</p><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in">SELECT task_id, user_id, task_date</p><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in">FROM task</p><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in">WHERE task_id IN (1, 2, 3);</p><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in"> </p><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in">ERROR: insert or update on table "task_history" violates foreign key constraint "fk_task_history_task_id"</p><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in">  Detail: Key (task_id)=(1) is not present in table "task".</p><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in"> </p><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in">Thanks,</p><p style="font-family:'calibri' , sans-serif;font-size:11pt;margin:0in 0in 0.0001pt 0in">Manfred</p></div> <hr /><br /><font face="Arial" size="1">Information in this e-mail may be confidential. It is intended only for the addressee(s) identified above. If you are not the addressee(s), or an employee or agent of the addressee(s), please note that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this e-mail in error, please notify the sender of the error.</font></div></blockquote>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: FK constraint question
  2020-04-01 13:49 FK constraint question Heinemann, Manfred (IMS) <HeinemannM@imsweb.com>
@ 2020-04-22 16:31 ` Ashutosh Sharma <ashu.coek88@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Ashutosh Sharma @ 2020-04-22 16:31 UTC (permalink / raw)
  To: Heinemann, Manfred (IMS) <HeinemannM@imsweb.com>; +Cc: pgsql-sql@lists.postgresql.org <pgsql-sql@lists.postgresql.org>

Hi,

Do you have multiple task table created in your database?

Can you share the output of \d+ task_history?

On Wednesday, April 1, 2020, 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".
>
>
>
> Thanks,
>
> Manfred
>
> ------------------------------
>
> Information in this e-mail may be confidential. It is intended only for
> the addressee(s) identified above. If you are not the addressee(s), or an
> employee or agent of the addressee(s), please note that any dissemination,
> distribution, or copying of this communication is strictly prohibited. If
> you have received this e-mail in error, please notify the sender of the
> error.
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2020-04-22 16:31 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-04-01 13:49 FK constraint question Heinemann, Manfred (IMS) <HeinemannM@imsweb.com>
2020-04-01 15:29 ` Steve Midgley <science@misuse.org>
2020-04-22 15:50 ` Samed YILDIRIM <samed@reddoc.net>
2020-04-22 16:31 ` Ashutosh Sharma <ashu.coek88@gmail.com>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox