From: | Peter Geoghegan <pg(at)bowt(dot)ie> |
---|---|
To: | Utku <ugultopu(at)gmail(dot)com> |
Cc: | pgsql-novice(at)lists(dot)postgresql(dot)org |
Subject: | Re: How to UPSERT with optional updates? |
Date: | 2021-09-21 17:02:54 |
Message-ID: | CAH2-WzmoPqRxyFxDR_W8oeyRp4i3r05F295ELRKovRA_uA=GJQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
On Tue, Sep 21, 2021 at 9:58 AM Utku <ugultopu(at)gmail(dot)com> wrote:
> I'm trying to write a script for an optional upsert. That is, it is just like a regular insert or update, but in addition, the information of a given column should be updated, or be left as-is, is passed as well. That is:
>
> - Insert if does not exist.
> - If exists, check the parameters to understand if a particular column should be updated, or be left as-is.
The DO UPDATE portion of an upsert statement will accept a WHERE
clause that works in much the same way as a WHERE clause from a
regular UPDATE. You can decide whether you really want to update the
row, based on the row's actual contents, as well as the contents of
your EXCLUDED.* pseudo-row.
--
Peter Geoghegan
From | Date | Subject | |
---|---|---|---|
Next Message | Terry Buchanan | 2021-09-21 17:30:22 | Is a Digest Version of this List Available? |
Previous Message | Utku | 2021-09-21 13:43:21 | How to UPSERT with optional updates? |