Re: UPDATE ... ON CONFLICT DO NOTHING

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: UPDATE ... ON CONFLICT DO NOTHING
Date: 2017-03-14 15:46:02
Message-ID: 66b68c5a-2f4c-2755-e074-c51c4aafa0f2@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 03/14/2017 08:38 AM, Alexander Farber wrote:
> Yes, Adrian -
>
> On Tue, Mar 14, 2017 at 3:57 PM, Adrian Klaver
> <adrian(dot)klaver(at)aklaver(dot)com <mailto:adrian(dot)klaver(at)aklaver(dot)com>> wrote:
>
> On 03/14/2017 07:23 AM, Alexander Farber wrote:
>
>
> in _uids array I have all user ids of player.
>
> I want to merge his or her data, including reviews, to a single
> user id:
> out_uid.
>
> So I make a copy of related words_reviews records (where this
> user has
>
>
> Alright I see that you are setting out_uid above the INSERT.
> So you are INSERTing rows and if they CONFLICT you leave them alone
> and have the DELETE remove them, correct?
>
>
> that is correct and my question is:
>
> copying records for later INSERT ON CONFLICT DO NOTHING seems
> ineffective to me.
>
> I would prefer to just use UPDATE (for changing "uid" or "author"
> columns to out_uid value) - but how to handle the conflicts with UPDATE?

The more I think about it the more I think you are doing the same thing
as INSERT ON CONFLICT DO UPDATE, where if there is a PK conflict you
just want to update the values with data from excluded. There is
inverse logic in the function that I have not wrapped my head around
yet, so this is more a hunch then anything else.

>
> Thank you
> Alex
>
> P.S. I have just donated 20 Euro to paypal(at)postgresql(dot)eu
> <mailto:paypal(at)postgresql(dot)eu>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Антон Тарабрин 2017-03-14 15:55:51 Re: Table not cleaning up drom dead tuples
Previous Message Alexander Farber 2017-03-14 15:38:48 Re: UPDATE ... ON CONFLICT DO NOTHING