0

Im migrating an application from oracle to postgresql. In one of the functions that I already migrated I copy data from a different oracle db (db link in oracle, oracle_fdw extension in postgresql) from a few tables into a local table in my postgresql db. However, I`m getting the next error :

invalid byte sequence for encoding "UTF8": 0x00

I saw that some people had this kind of issue in this forum but they didnt try to copy the data directly from a remote database (they loaded data from a dump or from a csv..).

Some kind of idea what can I do ?

2
  • What is the Oracle DB encoding? Commented Jul 24, 2017 at 12:06
  • nls_characterset : IW8ISO8859P8 Commented Jul 24, 2017 at 12:13

2 Answers 2

3

PostgreSQL does not allow the “zero” character in character strings.

You'll have to sanitize the Oracle data before you can retrieve them from PostgreSQL.

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

11 Comments

What does it mean "Zero" character ? How can I filter the data before it comes to postgresql ? I run in postgresql the query insert into local_table select * from remote_table
With "zero character" I mean the character with ASCII (or UNICODE) code point 0. Ther error is thrown during the select from remote_table - some string column there contains such a character. You'll have to fix the data on the Oracle side.
I think that those just varchar columns that dont have any value - the null of varchar. So what exactly do I need to change ?
No, a NULL value would not be a problem. If you select the offending value like this in Oracle: SELECT dump(badcol, 16) FROM atable WHERE id = 42 you will see a byte 0x00 somewhere in there. That is the problem (replace badcol, atable, id and 42 with relevant values for your situation).
The error I got in postgresql doesnt specify which row has the problem - only the table_name and the column. How can I proceed from here ? for exmaple : insert into MANUIM select * from MANUIM_prod; ERROR: invalid byte sequence for encoding "UTF8": 0x00 CONTEXT: converting column "street" for foreign table scan of "manuim_prod", row 922311
|
2

Now it works with oracle_fdw 2.3.+ Here is code I used

select 'ALTER FOREIGN TABLE "'||table_schema||'"."'||table_name||'" ALTER COLUMN "'||column_name||'"  OPTIONS (ADD strip_zeros ''true'');' 
from information_schema."columns" c 
where table_name ='my_foreign_table_name'
and table_schema ='my_schema_name_where_foreign_table_created'
and udt_name in ('varchar', 'bpchar');

Comments

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.