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 1lBhI4-0007o1-S0 for pgsql-general@arkaria.postgresql.org; Mon, 15 Feb 2021 17:04:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lBhI3-0001N9-C5 for pgsql-general@arkaria.postgresql.org; Mon, 15 Feb 2021 17:04:03 +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 1lBhI3-0001My-4M for pgsql-general@lists.postgresql.org; Mon, 15 Feb 2021 17:04:03 +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 1lBhHz-0007bR-Fv for pgsql-general@lists.postgresql.org; Mon, 15 Feb 2021 17:04:02 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 009921012; Mon, 15 Feb 2021 12:03:57 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 15 Feb 2021 12:03:58 -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=e LQ39RHox975GD+Pf4cAkvGBkSVsOXdizL4B8l2UBgQ=; b=j5Vu1/CysuVFDYfez Ip6pf1iWjL9opzWej61fPyo8X/WVrX+R+S5qVQtVd3ln9+vmEvyOOdVsr90EDGsD WQBfrReJnxA27r0dqD8Hmq77DoE+j81aNu3dZNMffLpyTUxSeT83+74QET/5vKE4 cKCyR8TLJcvB2knQMw84e8VB5yU1RBM9dNNLmco/NFYBWGb2RyECTceYu9IoQs7v xd/wPQEixNzWHJe5mMaLTZ9JkM/WUVKX1YhUGSketSbTV7HfCJbJtONE46zhy8tC gTCupLYK3DS7eo/+rp56LilQuo+fL0mZnLgoSPsx9opZ8NRDaB7ii2LMmGPv4m2D fpAPg== 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=eLQ39RHox975GD+Pf4cAkvGBkSVsOXdizL4B8l2UB gQ=; b=XCA5YTH7zVP/qmtQQFDTrmbh5tIdQpPanFz1YfQIkERoa+2Q4oyBoVhEu diebg2VyM/5d6VJNyMRtzYVPRMI1y4SChL8YmQBgP5+TUirN+gRJdzZRw7odpIgW zaowZ8c69ZFA13rat9e3OmeU3R541rXkWNqHsgzMo0TyfZfdBtsOC033IwTYj/Xc N4epQ11BpFM1fbSryXVKe5qVuGOOmqS0JytZL4nFDRkWJGO0UTADZxwb29so3Sxl 3bK1LBsbITwBvYbaEBi0yphGAieXjpbkX5y37+x+TcJddqiqxKbTjB3/x34fGti0 OcBljMsktA3yRoHhuoUS1sLPv7qZQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrieekgdeludcutefuodetggdotefrodftvf 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 C599B1080066; Mon, 15 Feb 2021 12:03:56 -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: <27b05961-ead0-a75e-d90d-18ff8ea8259f@aklaver.com> Date: Mon, 15 Feb 2021 09:03:56 -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: > > > 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.klaver@aklaver.com