Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lBhCt-0007Tx-BU for pgsql-general@arkaria.postgresql.org; Mon, 15 Feb 2021 16:58:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lBhCs-0001lw-7n for pgsql-general@arkaria.postgresql.org; Mon, 15 Feb 2021 16:58:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lBhCs-0001lp-02 for pgsql-general@lists.postgresql.org; Mon, 15 Feb 2021 16:58:42 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lBhCn-0007YK-LP for pgsql-general@lists.postgresql.org; Mon, 15 Feb 2021 16:58:41 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 1F439FBC; Mon, 15 Feb 2021 11:58:36 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 15 Feb 2021 11:58:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=T WyU0l5ifc9pDXf8anpE5PuyamvzNtQEF/tYT7eq9iA=; b=VeWhHZIjJEvunkiE7 mVQw9zpDxJZA5XeS/UUNfs4qtxMyxTgkKnEiU8i+yIJmZQ0FLKBOG3IEDJwGtMs3 HWgfMtlYOlo0CnnMpKuoqrEVxEtw5lM+YAKKUZ6DsCw73KWMWHqu3w0Pp/Hx7kMZ xRelaO11pyMPiEVCqV+7hQG6mWcdldBoe4x4ENTxbnJp+rMCT6MqZ2CgS2RVmR/J x9qPAR1GM93OVqFe8Sl5LyEUHoZEXioiZZjsR2wdTX2420bJRbDwX74U2stdohFm IMfli5SiXtrNYw2Kvf02YwRy9aIFO3S+ZtJpfmYMqZyl74vhjZv6Aw3D68v10xdJ CdBhA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=TWyU0l5ifc9pDXf8anpE5PuyamvzNtQEF/tYT7eq9 iA=; b=vHytctBUg3aqmzoXQ3QKS3RaWmBM9/UeiF7sAfCSaSO3yTua3idI6lTNf Wa8uBRCJgD0CdjRAca9lfqchDSNXcJHgG7l+FAoV0R7dD/HVV4si4PFwmfxs/B43 f5J/Asw3A8TZ1kKCmWtcU556DAnALrbf/aFV+e5EKOvwuBhHMEo/qLQ7V+UEM6+p PXvCjdQfssvNoRN4iGsW3UHVzvXsnmWcU6YIlG4Mq+zjWqQ+eIDS9pZhMyyXg0QV vvC3vq0+Aj9+L44cJmq9qIQZaaDfvgxjQKiPX8sk/YlYShHFZ19Nrm2bAfIvKMkO yUKDk2oT8Cle62SE3PsfdH6141O/Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrieekgdeltdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuggftrfgrthhtvghrnhepveevfeevfeeugeffkeekhfegieeufffgteeujedvgffh ueejjefhkeejleegtdegnecukfhppeeljedruddufedrvddujedrvdejnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgr vhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.4] (97-113-217-27.tukw.qwest.net [97.113.217.27]) by mail.messagingengine.com (Postfix) with ESMTPA id 443F9108005C; Mon, 15 Feb 2021 11:58:35 -0500 (EST) Subject: Re: ADD FOREIGN KEY fails, but the records exist To: Ron , "pgsql-generallists.postgresql.org" References: <37d7ad6b-3da6-0778-47fe-e6256babb4ad@aklaver.com> <22cd11dc-b6de-9056-fbed-1c53065fd1e0@aklaver.com> From: Adrian Klaver Message-ID: <5be653a0-cd07-11c3-2ced-e7e250547c8f@aklaver.com> Date: Mon, 15 Feb 2021 08:58:34 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2/15/21 8:55 AM, Ron wrote: > > > On 2/15/21 10:27 AM, Adrian Klaver wrote: >> On 2/15/21 8:23 AM, Ron wrote: >>> On 2/15/21 10:17 AM, Adrian Klaver wrote: >>>> On 2/15/21 8:12 AM, Ron wrote: >>>>> Postgresql 12.5 >>>>> >> >>>> The error: >>>> >>>> DETAIL:  Key (amended_response_id, part_date)=(103309154, 2021-01-06 >>>> 00:00:00) is not present in table "employer_response" >>>> >>>> is pointing at 103309154 for amended_response_id = >>>> employer_response_id. You are showing an employer_response_id of >>>> 103309156 >>> >>> But my query's WHERE clause specifies "amended_response_id = >>> 103309154;"  (I've highlighted it, if you have a GUI MUA.) >> >> Yes but amended_response_id is referencing employer_response_id. So do >> you have a record that matches: >> >> employer_response_id   part_date >> >> 103309154              2021-01-06 00:00:00 > > 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) > Well since it is the same column(type) then it had to be something in the transfer of the data from Oracle to Postgres. What are the values on the Oracle end? > > -- > Angular momentum makes the world go 'round. -- Adrian Klaver adrian.klaver@aklaver.com