I'm striving to convert badly encoded data from my table. For instance, I have a field with Nadège
which should be Nadège
.
I tried using Postgres's functions convert
, convert_from
, convert_to
without much success.
db=# SHOW client_encoding;
client_encoding
-----------------
UTF8
(1 row)
db=# SHOW server_encoding;
server_encoding
-----------------
UTF8
(1 row)
db=# SELECT "firstName", encode("firstName"::bytea, 'hex') FROM contact;
firstName | encode
-----------+--------------------
Nadège | 4e6164c3a86765
Nadège | 4e6164c383c2a86765
(2 rows)
db=# SELECT "firstName", convert_from("firstName"::bytea, 'latin1') FROM contact WHERE "lastName" ILIKE 'crochard';
firstName | convert_from
-----------+----------------
Nadège | Nadège
Nadège | NadÃ\u0083¨ge
(2 rows)
db=# SELECT "firstName", convert("firstName"::bytea, 'utf8', 'latin1') FROM contact;
firstName | convert
-----------+------------------
Nadège | \x4e6164e86765
Nadège | \x4e6164c3a86765
(2 rows)
Using python I'm able to get the correct encoding with:
data.encode('latin1').decode('utf8')
Any hint on how to convert these wrongly encoded data in postgres ?