Error in convert_from () | SQL_ASCII

0

When I try to use the convert_from function of postgresql I'm encountering the following error:

invalid byte sequence for encoding "UTF8": 0xe3 0x30 0x30

I have already looked here in the stack and I have not found anything that can help me.

    
asked by anonymous 03.10.2017 / 00:01

1 answer

0

You need to identify the encoding of all your entries and exits to avoid confusion and not lose the original data along the way.

First, you need to identify the encoding in which your .txt file was written.

On *nix systems you can use the file utility to detect encoding of a file:

$ file entrada1.txt 
entrada1.txt: UTF-8 Unicode text

$ file entrada2.txt 
entrada2.txt: ISO-8859 text

$ file entrada3.txt 
entrada3.txt: ASCII text, with CRLF line terminators

Identifying the encoding of each file, you will be able to properly convert them using the convert_from() function:

-- Lendo arquivo UTF-8/UNICODE
SELECT convert_from( pg_read_binary_file( 'entrada1.txt' ), 'UTF8' );

-- Lendo arquivo LATIN-1 / ISO-8859-1
SELECT convert_from( pg_read_binary_file( 'entrada2.txt' ), 'LATIN1' );

-- Lendo arquivo puramente ASCII
SELECT convert_from( pg_read_binary_file( 'entrada3.txt' ), 'SQL_ASCII' );
    
03.10.2017 / 18:36