Home > Enterprise >  How to transcode Unicode to ISO 8859-1 with postgres 13
How to transcode Unicode to ISO 8859-1 with postgres 13

Time:04-20

How can I transcode a UTF-8 string to Latin1 with PostgreSQL 13 ?

I've read this SO thread but the functions convert(), convert_from() and convert_to() no longer exist starting from Postgres 13.

EDIT: the solution is given by Laurenz Albe, who pointed out that the functions still exist. I was only afterwards that I noticed:

  • Google made me land on the manual for 8.2, for which convert() has a different signature than in version 8.3
  • I tried the 8.2 SQL code that resulted in ERROR: syntax error at or near "USING"
  • I couldn't find the function in the version 13 docs, because:
  • the function manual has been moved to Binary functions

So the correct SQL should have been:

SELECT convert('text_in_utf8', 'UTF8', 'LATIN1');

CodePudding user response:

convert_from and convert_to still exist, but they cannot convert from text to text because text is always a string in the database encoding. Strings in other encoding can only be stored as bytea.

I cannot guide you any further, because you didn't tell us what problem you are trying to solve.

  • Related