Re: Best practice for: ERROR: invalid byte sequence for encoding "UTF8" - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Best practice for: ERROR: invalid byte sequence for encoding "UTF8"
Date
Msg-id 20070815120435.GA28485@svana.org
Whole thread Raw
In response to Best practice for: ERROR: invalid byte sequence for encoding "UTF8"  ("Ivan Zolotukhin" <ivan.zolotukhin@gmail.com>)
Responses Re: Best practice for: ERROR: invalid byte sequence for encoding "UTF8"  ("Ivan Zolotukhin" <ivan.zolotukhin@gmail.com>)
List pgsql-general
On Wed, Aug 15, 2007 at 03:41:30PM +0400, Ivan Zolotukhin wrote:
> Hello,
>
> Imagine a web application that process text search queries from
> clients. If one types a text search query in a browser it then sends
> proper UTF-8 characters and application after all needed processing
> (escaping, checks, etc) passes it to database. But if one modifies URL
> of the query adding some trash non-UTF-8 characters, database raises
> an error: invalid byte sequence for encoding "UTF8".
>
> What is the best practice to process such a broken strings before
> passing them to PostgreSQL? Iconv from utf-8 to utf-8 dropping bad
> characters?

Well, the query as given by the user is invalid, so returning an error
message complaining about the invalid byte sequence seems entirely
reasonable.

I don't see any reason to try and be smart. There's no way you can
"fix" the query.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment

pgsql-general by date:

Previous
From: "Dmitry Koterov"
Date:
Subject: How to trap exceptions inside PL/Perl functions?
Next
From: "Phoenix Kiula"
Date:
Subject: Re: Best practice for: ERROR: invalid byte sequence for encoding "UTF8"