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' );