From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | Rob Sargent <robjsargent(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: [EXTERNAL]: Re: [EXTERNAL]: Re: UPSERT in Postgres |
Date: | 2023-04-10 04:30:54 |
Message-ID: | 6638961e-cbcb-f21b-1b1c-347f01093e3e@aklaver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 4/9/23 19:16, Rob Sargent wrote:
> On 4/9/23 19:55, Louis Tian wrote:
>> Hi Alban,
>>
>> "I am not expecting an error here", by "here" I means when doing a
>> TRUE UPSERT (an upsert current does not exist in Postgres).
>> I am NOT referring to an "Insert on conflict do update" (which despite
>> its intention and wide acceptance is not fully equivalent to a true
>> upsert).
>> I understand the error I am getting now is due to not null constraint
>> given how "insert on conflict" works.
>>
>> An UPSERT checks whether a row exists, if so, it does an update, if
>> not it does an insert. This is the literal definition.
>
> This the part that's always eluded me: How does the client, the
> UPSERTer, come to hold an id and not know whether or not it's already in
> the database.
My use case is for bulk loading data into a table I know has data that
will create a PK/Unique violation with the inserted data. It's a quick
and dirty way to avoid queries that look for potential violations ahead
of time, basically 'Ask forgiveness' vs 'Get permission'.
--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Francisco Olarte | 2023-04-10 07:37:08 | Re: [EXTERNAL]: Re: [EXTERNAL]: Re: UPSERT in Postgres |
Previous Message | Rob Sargent | 2023-04-10 02:16:05 | Re: [EXTERNAL]: Re: [EXTERNAL]: Re: UPSERT in Postgres |