public inbox for [email protected]
help / color / mirror / Atom feedFrom: Adrian Klaver <[email protected]>
To: Juan Rodrigo Alejandro Burgos Mella <[email protected]>
To: Samuel Marks <[email protected]>
Cc: [email protected]
Subject: Re: How do I upsert depending on a second table?
Date: Tue, 23 Sep 2025 21:31:44 -0700
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAHbZ42xv5f-DrCnhrszKzmLrTQzrw1=3OYSyfEzM9rPVXAy_MQ@mail.gmail.com>
References: <CAMfPbcbjTE6=yVJjAyiNU=kM24e-0oLo8S1ZZ7dJZy3UKq+b3g@mail.gmail.com>
<CAHbZ42xv5f-DrCnhrszKzmLrTQzrw1=3OYSyfEzM9rPVXAy_MQ@mail.gmail.com>
On 9/23/25 17:25, Juan Rodrigo Alejandro Burgos Mella wrote:
> Hi Samuel
>
> Using ON CONFLICT is a headache.
Like any tool ON CONFLICT has usage it is best for, if you try to force
it do something it was not designed for then it will not perform as
expected. Stick to what it good at and it will not be a headache. It is
good at moving data into a table where the incoming data is a mix of
entirely new rows and changes to existing rows for which there is some
sort of arbiter to decide on whether there is a conflict or not.
> It's better to use the versatility of a Trigger: you have the full
> record at your fingertips, and if you're going to UPDATE, you have the
> previous record too.
https://www.postgresql.org/docs/current/sql-insert.html#SQL-ON-CONFLICT
"
The SET and WHERE clauses in ON CONFLICT DO UPDATE have access to the
existing row using the table's name (or an alias), and to the row
proposed for insertion using the special excluded table.
"
> There's much more control.
>
> Also, you can always count on the beloved foreign keys, which are also
> quite useful.
>
> Atte.
> JRBM
--
Adrian Klaver
[email protected]
reply
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 using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: How do I upsert depending on a second table?
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox