0

I'm trying to migrate Oracle data with 'we8mswin1252' encoding to my database which has 'UTF8' encoding.

I'm using foreign data wrapper.

I'm getting

invalid byte sequence error

What should i do?

1
  • Welcome to StackOverflow! Please read and follow the posting guidelines in the help documentation regarding on topic and how to ask. StackOverflow is not a coding or tutorial service. Commented Sep 14, 2016 at 15:14

1 Answer 1

2

Such errors can be caused by two things:

  • There may be zero bytes in your Oracle strings. That is allowed in Oracle (even though it is problematic), but forbidden in PostgreSQL.

  • It is easy to get data corruption in Oracle, because it is pretty sloppy with encoding checks and allows you to insert arbitrary illegal byte sequences when client encoding and server encoding are the same.

There are two approaches to dealing with this problem:

  • The correct way: fix the data on the Oracle side. oracle_fdw will support you by telling you which row in the result set caused the error.

  • The sloppy way: use a PostgreSQL database with database encoding sql_ascii, which will allow you to store anything in a string (except zero bytes).

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

2 Comments

Laurenz, thanks for your reply, but can we create a database with sql_ascii encoding separately ? We have set it up in utf8 format. Also, we can't edit oracle data.
Sure: CREATE DATABASE badchars ENCODING sql_ascii LC_COLLATE "C" LC_CTYPE "C" TEMPLATE template0; Then you should set the nls_lang option on the foreign data wrapper to either use WE8MSWIN1252 if you want the garbage data unchanged or AS32UTF8 if you want them converted to UTF-8 as good as possible. Zero bytes will still be a problem.

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.