Re: INSERT Trigger to check for existing records : Does this do what I hope it is doing?

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: hagen(at)datasundae(dot)com, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: INSERT Trigger to check for existing records : Does this do what I hope it is doing?
Date: 2020-11-25 17:43:36
Message-ID: 56dd17d9-eadb-df56-4df6-ba79e4bcc3ca@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 11/25/20 9:13 AM, Adrian Klaver wrote:
> On 11/25/20 8:43 AM, hagen(at)datasundae(dot)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(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mats Julian Olsen 2020-11-25 19:01:17 Re: postgres_fdw insert extremely slow
Previous Message hagen 2020-11-25 17:35:43 RE: INSERT Trigger to check for existing records : Does this do what I hope it is doing?