Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcv0V-0002BM-Gd for pgsql-general@arkaria.postgresql.org; Mon, 17 Jun 2019 17:01:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hcv0T-00048R-Rp for pgsql-general@arkaria.postgresql.org; Mon, 17 Jun 2019 17:01:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcv0S-00045j-I1 for pgsql-general@lists.postgresql.org; Mon, 17 Jun 2019 17:01:21 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcv0P-0005Rf-Cy for pgsql-general@postgresql.org; Mon, 17 Jun 2019 17:01:19 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 44C8B2232A; Mon, 17 Jun 2019 13:01:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 17 Jun 2019 13:01:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:from:to:cc:references:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=h 0zEHXBhmo49kwXexIu9TU8ZupjD5TLP+9kek/1t10w=; b=Wg8qJdg1bkMHJeIFA uYbj4CBg/uv7i4udRFFwBd1tNKFTRBF6R+0slevT9WtYjl5rRTwLtn/oYqOfHUw/ c1YRp/rwpzDnxegXpVoOM3fua2mIoe11gsrbwVMLUYuvReiaRmTuSeevTrOddozf 419tDTwGkqoUFpJjOFWpWUMdnWqQxEJMvKyFW8bb3CsgqsPDziUD/7RwatjwxQy9 TBi76ZgaxJJqe8i1yXuwM+FhQZeKwUd9tsGDQgIdCYNhS6tV7ZPUbApvc5uavf2d aPAJPfpZMICknGGKO41VTtrmNea7Dj519njn+Mp3lm9/SjUj+Ylp2tUoMdx1RzJl kGYKg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=h0zEHXBhmo49kwXexIu9TU8ZupjD5TLP+9kek/1t1 0w=; b=GO2VuorHh1nWw4NalTkb/lkg1kNy1HBqn/LuwBPCdIAuza4CCedugNKM1 KDCKbYczDI350le0fweNMoLN1WMsDBpI/KSzQbhwSBrubh81pRgFcddKhvEQldOq m8uwiFawTJz9IeMrwRHPTwbB01CZQDqmTm61JOQvQLPZHAttpOBOm+8EPw28Y+9T rEgB4HE9o5DUAH/mzTY5G12RnXWAMDisI5rFdswfj117XY30gZRoO993xWaTAXYZ FqJ6yqYL0swA6QkoX24hyFYpcZQx8D42uY31mNmdVFTqOgcpu/YsdVQcnRSz/9Ar Q7zdpga1IL3QrYyW3TdLf49d3g2rw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrudeijedguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefuhffvfhfkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecukfhppeehtddrudeljedrkedtrddvnecurfgrrhgrmhepmhgrihhlfhhrohhm pegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrh fuihiivgeptd X-ME-Proxy: Received: from ranger.suse (50-197-80-2-static.hfc.comcastbusiness.net [50.197.80.2]) by mail.messagingengine.com (Postfix) with ESMTPA id 2526F380088; Mon, 17 Jun 2019 13:01:15 -0400 (EDT) Subject: Re: Copy Bulk Ignore Duplicated From: Adrian Klaver To: =?UTF-8?Q?Leandro_Guimar=c3=a3es?= Cc: pgsql-general References: <87o92zpzba.fsf@gmail.com> <5380793b-0380-f494-c7a4-488770df3a3e@aklaver.com> Message-ID: <3e8bd3be-407f-8bcf-1b53-8dd0726c0116@aklaver.com> Date: Mon, 17 Jun 2019 10:01:14 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <5380793b-0380-f494-c7a4-488770df3a3e@aklaver.com> 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 6/17/19 9:22 AM, Adrian Klaver wrote: > On 6/17/19 9:06 AM, Leandro GuimarĂ£es wrote: > Please reply to list also. > Ccing list. >> Ugh My bad again. >> >> They are UNIQUE: >> CONSTRAINT unique_const_value_20190501_45 UNIQUE (customer_id, >> date_time, indicator_id, element_id), >> >> I've made a mistake typing "check constraint" before because these are >> partitioned tables and I have the CHECK CONSTRAINT to partition. >> >> Is that clear? > > Yes. > > To get back to the original issue, the problem is that when you COPY in > new data you may get rows that conflict on the above UNIQUE constraint, > correct? Assuming the above is correct, would not something like below work?: create table orig_tbl(id integer, fld_1 varchar, fld_2 integer, fld_3 varchar, CONSTRAINT u_idx UNIQUE(id, fld_1, fld_2)); \d orig_tbl Table "public.orig_tbl" Column | Type | Collation | Nullable | Default --------+-------------------+-----------+----------+--------- id | integer | | | fld_1 | character varying | | | fld_2 | integer | | | fld_3 | character varying | | | Indexes: "u_idx" UNIQUE CONSTRAINT, btree (id, fld_1, fld_2) create table tmp_tbl(id integer, fld_1 varchar, fld_2 integer, fld_3 varchar); insert into orig_tbl values (1, 'test', 3, 'test'), (2, 'foo', 5, 'bar'), (3, 'cat', 8, 'dog'); select * from orig_tbl ; id | fld_1 | fld_2 | fld_3 ----+-------+-------+------- 1 | test | 3 | test 2 | foo | 5 | bar 3 | cat | 8 | dog (3 rows) insert into tmp_tbl values (1, 'test', 3, 'test'), (4, 'fish', 6, 'bird'), (7, 'rabbit', 8, 'squirrel'), (10, 'plant', 2, 'animal'); select * from tmp_tbl ; id | fld_1 | fld_2 | fld_3 ----+--------+-------+---------- 1 | test | 3 | test 4 | fish | 6 | bird 7 | rabbit | 8 | squirrel 10 | plant | 2 | animal (4 rows) select * from tmp_tbl AS tt left join orig_tbl AS ot on (tt.id, tt.fld_1, tt.fld_2) = (ot.id, ot.fld_1, ot.fld_2) where ot.id is null; id | fld_1 | fld_2 | fld_3 | id | fld_1 | fld_2 | fld_3 ----+--------+-------+----------+----+-------+-------+------- 4 | fish | 6 | bird | | | | 7 | rabbit | 8 | squirrel | | | | 10 | plant | 2 | animal | | | | > >> >> Thanks for your patience! >> Leandro GuimarĂ£es >> > > -- Adrian Klaver adrian.klaver@aklaver.com