in reply to Perl and Postgresql: Invalid byte sequence for encoding "UTF8"
I ran into this recently myself with a project to insert E-mail messages into a PostgreSQL database. I solved it like so:
use utf8; use Encode; my $possibly_bad_utf8_data = get_data(); my $good_data = encode( "UTF-8", $possibly_bad_utf8_data );
The capitalization of the UTF-8 in the call to encode() is important, it tells encode to be "strict" about the UTF-8. It turns out use utf8; isn't 100% strict and hence can't be inserted into a strict mode PostgreSQL database.
Hope this helps.
Frank Wiles <frank@revsys.com>
www.revsys.com
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl and Postgresql: Invalid byte sequence for encoding "UTF8"
by StoneTable (Beadle) on Dec 23, 2006 at 18:59 UTC | |
by Anonymous Monk on Jun 17, 2009 at 12:04 UTC |