Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bPFv8-0002Xt-P2 for pgsql-jdbc@arkaria.postgresql.org; Mon, 18 Jul 2016 21:17:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bPFv7-0000BW-Vi for pgsql-jdbc@arkaria.postgresql.org; Mon, 18 Jul 2016 21:17:46 +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.84_2) (envelope-from ) id 1bPFud-00085c-OO for pgsql-jdbc@postgresql.org; Mon, 18 Jul 2016 21:17:15 +0000 Received: from plane.gmane.org ([80.91.229.3]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bPFua-0004BR-35 for pgsql-jdbc@postgresql.org; Mon, 18 Jul 2016 21:17:14 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1bPFuU-0005Yr-Ab for pgsql-jdbc@postgresql.org; Mon, 18 Jul 2016 23:17:06 +0200 Received: from ppp-93-104-113-216.dynamic.mnet-online.de ([93.104.113.216]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 18 Jul 2016 23:17:06 +0200 Received: from spam_eater by ppp-93-104-113-216.dynamic.mnet-online.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 18 Jul 2016 23:17:06 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Kellerer Subject: Re: COPY in Java? Date: Mon, 18 Jul 2016 23:16:49 +0200 Lines: 43 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ppp-93-104-113-216.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 In-Reply-To: X-Pg-Spam-Score: -3.9 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org John R Pierce schrieb am 18.07.2016 um 22:34: > I'm looking at the JDBC documentation at > https://jdbc.postgresql.org/documentation/head/index.html and not > seeing any mention of COPY and any semantics for using COPY FROM > STDIN or COPY TO STDOUT... google has a link to a 404 page with some > sort of CopyManager https://jdbc.postgresql.org/documentation/publicapi/index.html indeed returns a 404 > we may need to develop a specialized sort of sql loader to replace an > existing Oracle tool, we need to intercept bad rows and put them in > an exceptions file, while bulk loading the good data. I'm thinking > we batch N rows into COPY, and if a row faults, put it in the > exception pool then retry the batch without it. the source data > needs to be massaged before it can be fed to copy, so we can't use > COPY FROM filename ... The CopyManager is actually quite easy to use: org.postgresql.core.BaseConnection con = (BaseConnection)DriverManager.getConnection(....); CopyManager mgr = new CopyManager(con); Reader in = new BuffereReader(new FileReader("...")); mgr.copyIn("copy target_table from stdin with (...)", in); But I don't think it's suitable for what you need to do because: * The input file needs to be formatted so that COPY can handle it. * there is no way you can catch the bad rows with that. I assume the first problem could be solved by implementing your own Reader that "massages" each line while it reads the source file. But I don't think there is an efficient way to "catch" the bad rows through the Copy API. But you might be interested in http://pgloader.io/ which is a tool similar to SQL*Loader it supports more formats then COPY does. I have not worked with it however Thomas -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc