Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fGcru-0005nl-MF for pgsql-general@arkaria.postgresql.org; Thu, 10 May 2018 04:07:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fGcrt-000122-E6 for pgsql-general@arkaria.postgresql.org; Thu, 10 May 2018 04:07:49 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fGcrr-00011n-FA for pgsql-general@lists.postgresql.org; Thu, 10 May 2018 04:07:49 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fGcrn-0003eG-Sf for pgsql-general@lists.postgresql.org; Thu, 10 May 2018 04:07:45 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id B3DF621A4F; Thu, 10 May 2018 00:07:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 10 May 2018 00:07:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=7Gc7FnzaoQm+NEMSUCeUk0EXacgdD tztMzf2HfsD1K0=; b=ijZB4JryCVoTGnpD2yp2PcFpD6udiA10JdHuWJlriXAiZ XWuJX4qYVF3oPfo+ElajKz5jkwoJEIuu8Mik0gtqXWBvL2OjyR2AmB8Fo2t27SHU iOFdzhmFpvFpNVwD13xtIKFvXvMkAXS/Rq7r+uZcr5Kte/p9M5EdexoB6X/1lMQB V2NXo4SurqRgPrP/mLM8GhvZKlRB5O+Uv4NB+1PynXGyH10L6CqtaGg8sKt8ck+8 Hrs4QCOqQ6KvMy0cUMnvO0v4YHyHjkBWdCOGHtQTRqEsC+7nH6XkslYc0JQ1dms4 NfXGxIH6XFUPj3TEprLci5IM+g7RcI3B4GGthghZg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=7Gc7Fn zaoQm+NEMSUCeUk0EXacgdDtztMzf2HfsD1K0=; b=AB53Kg9nC4XS27GdO8J4o3 H0DgIBHDDQtiXdrrZopKFpNgWy7IeoA4tEtBfavShC8Ct8Nb031vgjU7DxFMNb6E f/xAHRjfWt/uLlXHM7DDR6VCBJzqhlojZgBsLEXar04ltI4LW5rszLlUOCZGSmxP Pzr737Pl9ruzAozbGA0U+FnoBE3Nwa+H30j+3/YhA5F1Cxl/6ZMAQEzM/OqOmw4o OGTuOHGmuUAWs1oMBOCyH7iREOQ9tiA3gQj3mzSPNIBkmuJaL5YVY0KufgG0kQDH rR+q1kWdTHOfhzOttD9G/vKQItD3MKBD0NKKPE1MPEeGl3eYg4W8x1ti8C/cJN6w == X-ME-Sender: Received: from [192.168.1.2] (unknown [71.212.135.74]) by mail.messagingengine.com (Postfix) with ESMTPA id 083B7E4076; Thu, 10 May 2018 00:07:41 -0400 (EDT) Subject: Re: ON CONFLICT DO UPDATE To: tango ward , "pgsql-generallists.postgresql.org" References: From: Adrian Klaver Message-ID: <8c437506-072c-7829-b649-fd2a4a5ecc69@aklaver.com> Date: Wed, 9 May 2018 21:07:41 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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