Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TWHiw-00039o-SU for pgsql-bugs@postgresql.org; Thu, 08 Nov 2012 02:20:06 +0000 Received: from mail-pa0-f46.google.com ([209.85.220.46]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TWHit-0003Og-LT for pgsql-bugs@postgresql.org; Thu, 08 Nov 2012 02:20:06 +0000 Received: by mail-pa0-f46.google.com with SMTP id hz1so1608593pad.19 for ; Wed, 07 Nov 2012 18:20:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding:x-gm-message-state; bh=30sZfsONN/jB8azKiehPc2VMWy2xU3AbkfYuL7nQJZ8=; b=kO54I6nce8yAGXD1PMZVRamJDG8xizkMtIfI9hpUVyaBI2ak5iKMOPCu5qpOY5IkqO RefOe/WfXwTS4Rm4CuQnAUu2mhtarraIdPke2VyJY6DXY31KEQW/jyoAKtlXhMritAvl Xx3L+kV/KJeqcFpzjJs61KvEEPDEHo8AR2LaDc2yJlr7PV00bQTtCjMuvpK88fOFcCxH mxZo/lBX5+jtSPIC6oo+1w+XZRgfLJ6fwtbsOLW8jLYHSoSvcMsDL7T1D2MxRAwvjiSv vZ3YpUPBh7BrQL4fY2EiFGghzSAZrWtFnwRxz2C2V0hywZesMY/VkU7StQXDbdL9USu7 C58w== Received: by 10.66.76.162 with SMTP id l2mr17856058paw.36.1352341201002; Wed, 07 Nov 2012 18:20:01 -0800 (PST) Received: from ayaki.localdomain (124-148-90-153.dyn.iinet.net.au. [124.148.90.153]) by mx.google.com with ESMTPS id ak10sm14178052pbd.24.2012.11.07.18.19.58 (version=SSLv3 cipher=OTHER); Wed, 07 Nov 2012 18:20:00 -0800 (PST) Message-ID: <509B16CC.5050905@ringerc.id.au> Date: Thu, 08 Nov 2012 10:19:56 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121016 Thunderbird/16.0.1 MIME-Version: 1.0 To: Saravanan Nagarajan CC: pgsql-bugs@postgresql.org Subject: Re: duplicate key value violates unique constraint "tableName_pk" References: In-Reply-To: X-Enigmail-Version: 1.4.5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQluZLV0UtW0HUsR9bwrxIs63tXc6Ct3l2Mm8bLPonTaUrsu9mdIZ6t8m21gqpy+0sl0fi2w X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201211/35 X-Sequence-Number: 34593 On 11/07/2012 07:21 PM, Saravanan Nagarajan wrote: > Hi , > > I am using "Copy From" while dumping bulk data into PGSQL DB from > file. While I am trying to insert the rows, if the primary key already > exists, the complete transaction terminated. > > Postgres cannot handle the constraint violations , i found it > into http://wiki.postgresql.org/wiki/COPY#Caveats_with_implementation . > > Is there any possible way to insert bulk data using "Copy From" with > REPLACE/IGNORE duplicates. Typically you COPY into a temporary or UNLOGGED table, then merge the data into the target table using appropriate `UPDATE ... FROM ... WHERE` and `INSERT ... SELECT ... WHERE` statements. -- Craig Ringer