5

I have a problem during bulk insert. I'm trying do bulk insert from file with encoding LATIN1 into table where database with encoding UTF8.

invalid byte sequence for encoding "UTF8": 0xc33f 

When I do SET CLIENT_ENCODING='LATIN1' and after do COPY from console, it works OK. but JDBC say me that he can't do SET CLIENT_ENCODING.

Please, could you suggest solution how I can workaround problem. Thanks!

2
  • Why can't you send a set client_encoding statement as raw sql in jdbc? Commented Jun 8, 2011 at 10:00
  • yep, as sql query execute by means jdbc. Aslo I tried add settter into stored procedure before COPY operation but the same error. Commented Jun 8, 2011 at 14:22

1 Answer 1

5

Try to set allowEncodingChanges connection parameter to true to allow (temporarily) changing client encoding to LATIN1. According to Table 22-2 PostgreSQL should handle automatic character set conversion between LATIN1 (client) and UTF8 (server).

The client_encoding setting is set by the driver and should not be altered. If the driver detects a change it will abort the connection. There is one legitimate exception to this behavior though, using the COPY command on a file residing on the server's filesystem. The only means of specifying the encoding of this file is by altering the client_encoding setting.

Enable this only if you need to override the client encoding when doing a copy.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! It's a solution.May be you know, what is consequence for allowEncodingChanges = true.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.