From: Adrian Klaver <adrian.klaver@aklaver.com>
To: tango ward <tangoward15@gmail.com>
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: ON CONFLICT DO UPDATE
Date: Wed, 9 May 2018 21:07:41 -0700
Message-ID: <8c437506-072c-7829-b649-fd2a4a5ecc69@aklaver.com> (raw)
In-Reply-To: <CAA6wQL+Os7BMmowFQqBYLZJdmw6faGn+xbe=OpRa7u7mqC=joQ@mail.gmail.com>
References: <CAA6wQL+Os7BMmowFQqBYLZJdmw6faGn+xbe=OpRa7u7mqC=joQ@mail.gmail.com>
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
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: adrian.klaver@aklaver.com, tangoward15@gmail.com
Subject: Re: ON CONFLICT DO UPDATE
In-Reply-To: <8c437506-072c-7829-b649-fd2a4a5ecc69@aklaver.com>
References: <CAA6wQL+Os7BMmowFQqBYLZJdmw6faGn+xbe=OpRa7u7mqC=joQ@mail.gmail.com> <8c437506-072c-7829-b649-fd2a4a5ecc69@aklaver.com>
* 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