1

I have a PostgreSQL database which uses an arcane text encoding, and I can't change that. Is there a way tostore text in UTF-7 transparently (for the informed client) so that the database engine doesn't complain that it cannot convert Unicode characters, but the client can still use any Unicode characters out there? I can do this conversion manually, but I hope there is a way to do it without manual conversion.

1 Answer 1

3

You can use SQL_ASCII, which tells the database to pass the bytes for text transparently without any validation or conversion.

This is usually a terrible idea that leads to a horrid mix of incompatible and mismatched text encodings in a DB, with some apps inserting UTF-8, others latin-1, etc. It is an option if you need to work with an encoding that the database cannot actually understand, though.

Your alternative would be to add support for utf-7 to PostgreSQL. This might not be too difficult as all the encoding handling is pretty well abstracted.

2
  • I can't change the database encoding, and I don't control the database server. Is it possible to use SQL_ASCII as the client encoding if the server encoding is something else? Nov 24, 2013 at 23:21
  • @AlexeiAverchenko If the server encoding is fixed, your only option would be to store data as bytea or something like base64 text and do your encoding/decoding client side. That'll be painful. Nov 25, 2013 at 1:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .