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 1hbuEP-00054Y-Oo for pgsql-general@arkaria.postgresql.org; Fri, 14 Jun 2019 21:59:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hbuEO-0000jA-72 for pgsql-general@arkaria.postgresql.org; Fri, 14 Jun 2019 21:59:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hbuEM-0000if-DJ for pgsql-general@lists.postgresql.org; Fri, 14 Jun 2019 21:59:31 +0000 Received: from [66.111.4.28] (helo=out4-smtp.messagingengine.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hbuEI-0003Sv-9I for pgsql-general@postgresql.org; Fri, 14 Jun 2019 21:59:30 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 9BB4D222E9; Fri, 14 Jun 2019 17:59:04 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 14 Jun 2019 17:59:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=r 6IkfN55snF97gnAGQteRqg7d8xRnPV3etIl9iH+jhE=; b=ZeHeEVRG8m+l4V7k7 dnr3IwAHmuMtc87kN10L0rlMDrQxyqNU8OLtfdtLbrgXEMsIaueM7OJtEVa3vMcV erR4UFB1CMaCB/1jK3QqbGOmZeV55o7W2qctv0lAcasE0d/RCPckOfbS4QiKEFFK WEkg++YqZVrhpJqZUJtVADkobQYXN92/D/i7bY4r/WrFxlCITIlrFG3bgk0wKh1Y QnFyAKFKlglvBbeyn5HCdinlaCMdPIgx4/z4hqojf4yOquMz02Y2ZnKWgPi9VuDw ot7+wdvLwel6deMNNIIktFmMkG3OIiBsxOF4WIOllkNNbZbZH0OfvkE7PFIYfDYY lNy4A== 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-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=r6IkfN55snF97gnAGQteRqg7d8xRnPV3etIl9iH+j hE=; b=KCbIDBUrulIi9PjKPKHsXb+sPq7Jkexa2CGG1ki2jfSVg6Wm69XMWsd0S IEu3RZyHzuHgenG2Xtv1V5cqe9EqNPCRIxaeToQsBsd8Nu1OunexASp0ARmoaI47 PkR0a0Q5tvaff36JdgD1pWVnl1Du57HFvlAatVQxU/nirChN8OKOMOjwoP1H9wWj /rdT4swYWmXTeHp29b6+WohAY07gdHqfZGoXl/HZZfU22ycuJ8QT4zlsG8NvPoVg FoReXqVzf+wG6HP2dbFjuP912pdMBWXYKMPkW4pIH7Cy4gvkHcDZTZZF4mVwF46y Um9hsj9Wxuxu54e67JnnMUVM0YLoQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrudeivddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne goufhushhpvggtthffohhmrghinhculdegledmnecujfgurhepuffvfhfhkffffgggjggt gfesthekredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrih grnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucffohhmrghinhepthdurdhn rghmvgdpghhithhhuhgsrdhiohdpthdvrdhnrghmvgenucfkphephedtrdduleejrdektd drvdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghk lhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt 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 C039C8005B; Fri, 14 Jun 2019 17:59:03 -0400 (EDT) Subject: Re: Copy Bulk Ignore Duplicated To: =?UTF-8?Q?Leandro_Guimar=c3=a3es?= , pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: Date: Fri, 14 Jun 2019 14:59:02 -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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 66.111.4.28 (deferred) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 6/14/19 2:04 PM, Leandro Guimarães wrote: > Hi, >    I have a scenario with a large table and I'm trying to insert it via > a COPY command with a csv file. > >    Everything works, but sometimes my source .csv file has duplicated > data in the previously fulfilled table. If I add a check constraint and > try to run the COPY command I have an error that stops the whole insertion. > >   I've tried to put the data in a tmp table and fill the main using > distinct this way (the fields and names are just examples): > > INSERT INTO final_table values (name, document) >    SELECT DISTINCT name, document >    FROM tmp_TABLE t1 >    WHERE NOT EXISTS ( >    SELECT 1 FROM final_table t2 >    WHERE (t2.name , t2.document) >    IS NOT DISTINCT FROM (t1.name , t1.document)) > > The problem is that my final_table is a large (and partitioned) table > and this query is taking a long time to execute. > > Someone have any idea (really guys anything would be great) how to solve > this situation? I need to ignore duplicates instead to have some error. pg_bulkload?: https://ossc-db.github.io/pg_bulkload/pg_bulkload.html "PARSE_ERRORS = n The number of ingored tuples that throw errors during parsing, encoding checks, encoding conversion, FILTER function, CHECK constraint checks, NOT NULL checks, or data type conversion. Invalid input tuples are not loaded and recorded in the PARSE BADFILE. The default is 0. If there are equal or more parse errors than the value, already loaded data is committed and the remaining tuples are not loaded. 0 means to allow no errors, and -1 and INFINITE mean to ignore all errors. " > > I'm using*PostgreSQL 9.4* so I can't use "ON CONFLICT" and upgrade is > not an option. > > Thanks and Kind Regards! > > > Leandro Guimarães > -- Adrian Klaver adrian.klaver@aklaver.com