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 1khypX-00030C-Ts for pgsql-general@arkaria.postgresql.org; Wed, 25 Nov 2020 17:43:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1khypW-00036n-El for pgsql-general@arkaria.postgresql.org; Wed, 25 Nov 2020 17:43:46 +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 1khypW-00036f-77 for pgsql-general@lists.postgresql.org; Wed, 25 Nov 2020 17:43:46 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1khypR-0006de-1M for pgsql-general@lists.postgresql.org; Wed, 25 Nov 2020 17:43:45 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 0BBF4C2A; Wed, 25 Nov 2020 12:43:37 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 25 Nov 2020 12:43:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:from:to:references:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=O 1j91823QZmppAq7i4JkR6dy6fGKTragcsrJQh9BWBg=; b=QSrvvycTLZi6e7XkN 7qUw4/qjlY7zNMYmYXm9kocZIZNssS/6yjtNQ6H2v8ZGI6obT+WR60tXtOyEqjKV j4Rx526U65iwve4Y6wl3W6cVBjY7Jbo0824Ws9FpuHpzazkX6h0KuElrWYVAWO0N CAPL/Zsx38GP862P5FuNNkMMqA4pxgNiO9IDWc40EdLb48/w73+evK+vmdCT3/On W0Q6PZ816vq2sQS3tlaz99YDu7BrGUijbM1VHgINiVbtL+zDaEsBAd9XRm3Sa6wo N/8qbEve158eTrYQOAXVohuzoGmgr6BTf6I1DjupCx0haWsvXYdGBjCYlM3AmK+j J89vw== 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=fm1; bh=O1j91823QZmppAq7i4JkR6dy6fGKTragcsrJQh9BW Bg=; b=Duw6KJU2RMsWmP1QvebcBOo+DgTnbKEuYPx02Z9TViNvWr0slKJRN42e8 ZoxkQu8uTLWjw05P0dmn2gyX0xtdmgMVi9stJJ8QRRC2JX9B1nco4B11W9ci14qj 926tQtqsv3mgYJnVCOz8+qpSkZ+3s3k00wkzpioQrtfaALn5RgWvAB7xF5GnzdPq ciynAJkT3J4/VQpgCo7Y7V1xqqd4vVy1B9IxSIkYYig0fHr2dv59UghdCba9pfT5 0pu3Zv2EBiX5wYJ/WaBgrr7/oFrZyrZoN8w5l/RKFQKa6LjIMPpgtic3Z3kf3YDy 2TLh4Qe3JDqrQ60apMNnDSw0dsa0g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudehtddguddthecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepuffhvfhfkffffgggjggtgfesth ekredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpefhleekve ehgeffgfekjeffhfdujeeukeeivefhudegkeelgfefgeevheefieeiteenucfkphepjeeh rddujedvrdduledrudefleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: from [192.168.1.4] (75-172-19-139.tukw.qwest.net [75.172.19.139]) by mail.messagingengine.com (Postfix) with ESMTPA id 11AA63064AA6; Wed, 25 Nov 2020 12:43:36 -0500 (EST) Subject: Re: INSERT Trigger to check for existing records : Does this do what I hope it is doing? From: Adrian Klaver To: hagen@datasundae.com, pgsql-general@lists.postgresql.org References: <1fc1fb9e-684f-d028-3f9b-fcfaf1f12f65@aklaver.com> <3e1051a4-98d4-4a59-f382-5b82efa4c095@datasundae.com> <000e01d6c036$fda479b0$f8ed6d10$@datasundae.com> <2ecce3f7-f298-7fd2-f470-5cf9a71b349c@datasundae.com> <4131ec0f-7dfa-d170-8312-d4fa3fc7ec0f@aklaver.com> <204a1ad6-fd56-fa19-2211-cde267810b92@datasundae.com> <07cf01d6c34a$157bf610$4073e230$@datasundae.com> <5d6937c6-d34d-91b1-6fe7-81a9ef2007ed@aklaver.com> Message-ID: <56dd17d9-eadb-df56-4df6-ba79e4bcc3ca@aklaver.com> Date: Wed, 25 Nov 2020 09:43:36 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <5d6937c6-d34d-91b1-6fe7-81a9ef2007ed@aklaver.com> 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 11/25/20 9:13 AM, Adrian Klaver wrote: > On 11/25/20 8:43 AM, hagen@datasundae.com wrote: >> Adrian, >> > > Until the previous questions are addressed the above is not doable. > >> >> 3. Not positive the IF is doing what I want,  but if I copy a >> sfdc.dealid into the same_test() parameter field the FUNTION does >> update the hygiene_119.status field properly. To me, it appears I just >> need a way to iterate through and  insert one hygiene_119.dealid in >> the same_test parameter field. Then the UPDATE should flag all the >> hygiene_119 records as SAME or NEW. Obviously I don't REALLY need both >> flags as the absence of a flag would indicate status too. > > Before continuing with the function I would try some SELECT functions > that do what you want. > Would probably help if I expanded on that. So to find dealids that are new, something like: SELECT new_data.dealid FROM hygiene_119 AS new_data LEFT JOIN sfdc sp AS old_data ON new_data.dealid = old_data.dealid WHERE old_data.dealid IS NULL; The LEFT JOIN will return all the dealids from hygiene_119 and if a dealid does not exist in sfdc the fields for it will be set to NULL. So by filtering on old_data.dealid IS NULL you find the dealids that exist in the new data but not the old. >> Best, >> >> Hagen >> -- Adrian Klaver adrian.klaver@aklaver.com