pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-jdbc@postgresql.org
Subject: Re: COPY in Java?
Date: Mon, 18 Jul 2016 23:16:49 +0200
Message-ID: <nmjh08$qql$1@ger.gmane.org> (raw)
In-Reply-To: <b4c16a4a-a410-38c5-becc-fc5f1d10cc7c@hogranch.com>
References: <b4c16a4a-a410-38c5-becc-fc5f1d10cc7c@hogranch.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

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



view thread (5+ messages)  latest in thread

Message-ID: <nmjh08$qql$1@ger.gmane.org>
Permalink:  ../nmjh08$qql$1@ger.gmane.org/
Also on:    postgresql.org/message-id/nmjh08$qql$1@ger.gmane.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: spam_eater@gmx.net
  Subject: Re: COPY in Java?
  In-Reply-To: <nmjh08$qql$1@ger.gmane.org>
  References: <b4c16a4a-a410-38c5-becc-fc5f1d10cc7c@hogranch.com> <nmjh08$qql$1@ger.gmane.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox