Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

Postgresql and UTF8 to Latin1 conversion?

$
0
0

We have a Postgresql database where the data is in Latin1. Apparently someone loaded some UTF8 encoded data into it since when I select data from some of the columns, I get stuff like:

SELECT symptoms from client
- -
"huvudvärke"
- -

where “ä” should be “ä”. I could handle it with replace, ie.:

UPDATE client SET symptoms=replace(symptoms, 'ä', 'ä');

I tried a couple of solutions I found, like using convert and convert_to but that leaves the data looking like "huvudv303244rke".

Is there an existing solution to my problem?

EDIT:

SELECT symptoms, symptoms::bytea from client
- -
"huvudvärke";"huvudv303203302244rke" 
- -

After the UPDATE above, query with symptoms::bytea outputs:

SELECT symptoms, symptoms::bytea from client
- -
"huvudvärke";"huvudv303244rke" 
- -

EDIT2:

select version();
"PostgreSQL 9.2.9, compiled by Visual C++ build 1600, 64-bit"

show client_encoding; --I'm using pgAdmin III 1.18.1
"UNICODE"

show server_encoding;
"UTF8"

SELECT symptoms, convert(convert_to(symptoms, 'utf-8'), 'latin-1', 'utf-8')::text from client;
"huvudvärke","huvudv303203302203303202302244rke"

Viewing all articles
Browse latest Browse all 1138

Trending Articles