Re: ON CONFLICT DO UPDATE - Mailing list pgsql-general

From Adrian Klaver
Subject Re: ON CONFLICT DO UPDATE
Date
Msg-id 8c437506-072c-7829-b649-fd2a4a5ecc69@aklaver.com
Whole thread Raw
In response to ON CONFLICT DO UPDATE  (tango ward <tangoward15@gmail.com>)
Responses Re: ON CONFLICT DO UPDATE  (tango ward <tangoward15@gmail.com>)
Re: ON CONFLICT DO UPDATE  (tango ward <tangoward15@gmail.com>)
List pgsql-general
On 05/09/2018 07:04 PM, tango ward wrote:
> 
> Hi,
> 
> Sorry for asking question again.
> 
> I would like to know if there's a workaround for this. I need to insert 
> Student Balance data into a table. The source data have duplicate values 
> for student_id, school_id and campus_name. My StudentBalance model in 
> Djano have Class Meta of:
> 
> class Meta:
>          unique_together = (
>              "school",
>              "student_id",
>              "campus_name"
>          )
> 
> Searched online and found this magical tool called ON CONFLICT DO 
> UPDATE. I played around with it, made it work but there's a problem. The 
> balance data is not being updated which is because it's not in class 
> Meta with unique_together. I would like to know if there's a way to 
> update the data in Student Balance column without adding it to the class 
> Meta?

I doubt that Meta has anything to do with the balance not being updated. 
What the Meta does is set up a UNIQUE index over the school, student_id 
and campus_name columns. I am going to say the issue is with ON CONFLICT 
DO UPDATE clause you create on the table. To help solve this we need:

1) The schema of the table StudentBalance points to.

2) The ON CONFLICT DO UPDATE clause you created on the table.

> 
> 
> Thanks,
> J


-- 
Adrian Klaver
adrian.klaver@aklaver.com


pgsql-general by date:

Previous
From: Chandru Aroor
Date:
Subject: Re: New install of 9.5.12 missing default PostgreSQL DB
Next
From: tango ward
Date:
Subject: Re: ON CONFLICT DO UPDATE