0
When trying to use the function convert_from of postgresql I am facing the following error:
invalid byte sequence for encoding "UTF8": 0xe3 0x30 0x30
I’ve looked here in the stack and found nothing that can help me.
0
When trying to use the function convert_from of postgresql I am facing the following error:
invalid byte sequence for encoding "UTF8": 0xe3 0x30 0x30
I’ve looked here in the stack and found nothing that can help me.
0
You need to identify the encoding of all its inputs and outputs to avoid confusion and not lose the original data along the way.
First, you need to identify the encoding in which your file .txt was recorded.
In systems *nix you can use the utility file to detect the encoding 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 convert them properly using the function convert_from():
-- 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' );
Browser other questions tagged postgresql character-encoding
You are not signed in. Login or sign up in order to post.
What is your intention to use the function
convert_from()? Have a sample of input ? What is the expected output ?– Lacobus
I have a file . txt, I take it as bytea, I need to read this file and get some information and save it to the base. Example : convert_from(NEW.file, 'SQL_ASCII'), returns me a text without special characters.
– Mateus Veloso
What is the
encodingof your file.txt? What is theencodingof your database ? What is theencodingoutput that receives the converted content returned byconvert_from()?– Lacobus
@Lacobus File : ? ( I’m not sure, is generated on the machine of the client "WINDOWS") DBA : UTF-8 , OUTPUT : SQL_ASCII
– Mateus Veloso