Re: ADD FOREIGN KEY fails, but the records exist

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Ron <ronljohnsonjr(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: ADD FOREIGN KEY fails, but the records exist
Date: 2021-02-15 17:03:56
Message-ID: 27b05961-ead0-a75e-d90d-18ff8ea8259f@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2/15/21 8:55 AM, Ron wrote:
>
>

> The time portions of the part_date fields don't match...
>
> sides=> ALTER TABLE employer_response
>     ADD CONSTRAINT amended_response_fk FOREIGN KEY
> (amended_response_id, part_date)
>         REFERENCES employer_response(employer_response_id, part_date)
>     ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED ;
> ERROR:  insert or update on table "employer_response_p2021_01" violates
> foreign key constraint "amended_response_fk"
> DETAIL:  Key (amended_response_id, part_date)=(103309154, 2021-01-06
> 00:00:00) is not present in table "employer_response".
> sides=>
>
> sides=> select employer_response_id, amended_response_id, part_date
> from strans.employer_response
> where amended_response_id = 103309154;
> employer_response_id | amended_response_id | part_date
> ----------------------+---------------------+---------------------
>             103309156 | *103309154 *| 2021-01-06*00:00:00*
> (1 row)
>
> sides=>
> sides=>
> sides=> select employer_response_id, amended_response_id, part_date
> from strans.employer_response
> where employer_response_id = 103309154;
> employer_response_id | amended_response_id | part_date
> ----------------------+---------------------+---------------------
> *103309154* |                     | 2021-01-06 *15:14:03*
> (1 row)

To add to my previous post regarding the part about the data transfer
process. You might look for code that did something like:

select current_date::timestamp;

current_date
---------------------
2021-02-15 00:00:00

In other words turned a date into a timestamp.

>
>
> --
> Angular momentum makes the world go 'round.

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Guyot 2021-02-15 17:24:25 Re: How to post to this mailing list from a web based interface
Previous Message Ron 2021-02-15 17:02:37 Re: ADD FOREIGN KEY fails, but the records exist