Skip site navigation (1) Skip section navigation (2)

Perl/PostgreSQL INSERT/UTF-8 problem

From: Madison Kelly <linux(at)alteeve(dot)com>
To: pgus-general(at)postgresql(dot)org
Subject: Perl/PostgreSQL INSERT/UTF-8 problem
Date: 2008-07-08 20:05:36
Message-ID: (view raw or whole thread)
Lists: pgus-general
Hi all,

   I've got a problem INSERTing a value into my DB via my perl program. 
It's a French character 'é', and my DB is set to UTF8, but the error is:

INSERT INTO customer_data (cd_cust_id, cd_variable, cd_value, 
added_user, added_date, modified_user, modified_date) VALUES (1, 
'CustServiceTypeDisplay_F', 'Résidence', 1, now(), 1, now());

DBD::Pg::db do failed: ERROR:  invalid byte sequence for encoding 
"UTF8": 0xe97369
HINT:  This error can also happen if the byte sequence does not match 
the encoding expected by the server, which is controlled by 

   When I manually run the INSERT, it works, so I know the problem is in 
perl somewhere. Now then, I setup my script with this:

# Setup for UTF-8 mode.
binmode STDOUT, ":utf8:";

   When I create my PgSQL connection, I use:

$dbh=DBI->connect($db_connect_string, $$conf{db}{user}, $$conf{db}{pass},
	RaiseError => 1,
	AutoCommit => 1,
	pg_enable_utf8 => 1
) or die ...;

   I push a pile of queries into an array (referenced) and run them like 

# Sanity checks stripped for the email
foreach my $query (@{$sql})
	print "Query: [$query]\n";
	$dbh->do($query) or $error.=$DBI::errstr.", ";

   Lastly, my database itself is set to UTF8:

SET client_encoding = 'UTF8';

   I've tried knocking out the 'pg_enable_utf8 => 1' line in case I was 
dealing with double-encoding, but that didn't help.

   Any tips/ideas?



pgus-general by date

Next:From: Joshua D. DrakeDate: 2008-07-22 19:49:10
Subject: Small update
Previous:From: Joshua D. DrakeDate: 2008-07-02 20:12:06
Subject: Re: Draft bylaws are now available

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group