Re: COPY support implemented

From: Per-Olof Noren <pelle(at)alma(dot)nu>
To: Kris Jurka <books(at)ejurka(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: COPY support implemented
Date: 2004-01-12 18:34:11
Message-ID: 1073932451.25461.31.camel@wpernor
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi Kris,

On Tue, 2003-12-30 at 09:25, Kris Jurka wrote:
> With the introduction of the V3 protocol in 7.4 it is now possible to
> support the COPY protocol in the JDBC driver. Before it was impossible to
> recover from errors and the Connection had to be abandoned. This patch
> implements support for COPY based on the API proposed by Michael
> Adler's original patch of about a year ago.

This is great news, as I'm currently working on a project that could
benefit from being able to run copy on a client machine.
I have patched the driver from the 7.4.1 src distro with the patch and
it compiled successfully.

After giving it a spin (which actually failed due to another reason,
more on that below) I have a little suggestion.

Consider this simple example (which happen to be my very code) :

String filename = "myfile.csv";
String sql = "COPY <<tablename>> FROM STDIN";
PGConnection pgConnection =
(org.postgresql.PGConnection) connection;

CopyManager copy = pgConnection.getCopyAPI();
FileInputStream fis = new FileInputStream(filename);
copy.copyInQuery(sql, fis);

The reason for using copyInQuery is that I need to be able to specify
the delimiter. I'm reasoning that i'm probably not alone on this.

My suggestion is one of the following:

Add CopyManager.copyIn(String tName, InputStream is, String delimiter);

Or add Javadoc that clearly states that the query
*MUST* be using "FROM STDIN" or the server will start looking locally
for the file, giving an FileNotException.

Ok, now to my litte trouble.
The database is encoded in LATIN1 running on pgsql 7.4.1.
I'm running the above code on a different machine running linux using
locale "sv_SE". The file I'm trying to import is encoded in ISO-8859-1.
Then running the above code I get the following error:
org.postgresql.util.PSQLException: ERROR: could not convert UTF-8
character 0x00f6 to ISO8859-1

This must be the JVM's encoding being set to UTF-8, right?
Or do I need to specify the encoding in the jdbc url or something?

Thanx in advance

Per-Olof Norén
Curalia AB

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message ritchie 2004-01-12 18:45:44 Re: COPY support implemented
Previous Message Kris Jurka 2004-01-12 17:43:09 Re: Warnings during compile of 7.4.1 driver under jdk1.4.2_03