From: Mario Emmenlauer <mario@emmenlauer.de>
To: Michael Lewis <mlewis@entrata.com>
Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: Re: Is it possible to write a generic UPSERT?
Date: Fri, 13 Nov 2020 10:28:01 +0100
Message-ID: <56e86aee-1541-ee4a-0c58-8a13c622b9cf@emmenlauer.de> (raw)
In-Reply-To: <CAHOFxGqciJKneQJpxhoiW50S9_VM24vcX+bjPz4WD6uC8FsbKw@mail.gmail.com>
References: <138f88db-9d18-dc06-3f55-bf0ae36541aa@emmenlauer.de>
<CAHOFxGqciJKneQJpxhoiW50S9_VM24vcX+bjPz4WD6uC8FsbKw@mail.gmail.com>
On 12.11.20 18:34, Michael Lewis wrote:
> On Thu, Nov 12, 2020 at 6:58 AM Mario Emmenlauer <mario@emmenlauer.de <mailto:mario@emmenlauer.de>> wrote:
>
> I can see how "ON CONFLICT" is very powerful. But that power seems
> often a burden for us. We would prefer something that is less manual
> effort for the specific use case. Basically, we would like:
> INSERT if not exist, and
> UPDATE _all_ non-conflicting fields in case of _any_ conflict
>
>
> If you do not have significant ratio of HOT (heap only tuple) updates that you want to preserve and you don't have sequences that are GENERATED AS ALWAYS
> (rather than BY DEFAULT), you could consider just doing a DELETE where the keys exist, then insert all the rows. It should be trivial to figure out the primary
> key or other unique index to match on.
>
> MERGE command is implemented for this use case in some DBMS, but not Postgres (yet?).
Actually I'm quite happy you suggest this, because its the one thing
that also came to my mind :) I was not really sure if this is a sane
idea. But it seems this could be the "easiest" way out, because its
short (like "easy to write") and works for all our use cases.
The main potential problem for my use case may be cascading deletes,
that I think we may want to use in the long run.
All the best,
Mario Emmenlauer
--
BioDataAnalysis GmbH, Mario Emmenlauer Tel. Buero: +49-89-74677203
Balanstr. 43 mailto: memmenlauer * biodataanalysis.de
D-81669 München http://www.biodataanalysis.de/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: mario@emmenlauer.de, mlewis@entrata.com
Subject: Re: Is it possible to write a generic UPSERT?
In-Reply-To: <56e86aee-1541-ee4a-0c58-8a13c622b9cf@emmenlauer.de>
References: <138f88db-9d18-dc06-3f55-bf0ae36541aa@emmenlauer.de> <CAHOFxGqciJKneQJpxhoiW50S9_VM24vcX+bjPz4WD6uC8FsbKw@mail.gmail.com> <56e86aee-1541-ee4a-0c58-8a13c622b9cf@emmenlauer.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox