Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iIvab-0005pQ-8a for pgsql-general@arkaria.postgresql.org; Fri, 11 Oct 2019 14:08:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iIvaZ-000245-UZ for pgsql-general@arkaria.postgresql.org; Fri, 11 Oct 2019 14:08:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iIvaZ-00023s-JJ for pgsql-general@lists.postgresql.org; Fri, 11 Oct 2019 14:08:15 +0000 Received: from ms-10.1blu.de ([178.254.4.101]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iIvaV-0005HS-V3 for pgsql-general@lists.postgresql.org; Fri, 11 Oct 2019 14:08:15 +0000 Received: from [188.174.95.79] (helo=localhost.unixarea.de) by ms-10.1blu.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.86_2) (envelope-from ) id 1iIvaU-0003Yf-F9; Fri, 11 Oct 2019 16:08:10 +0200 Received: from localhost.my.domain (localhost [127.0.0.1]) by localhost.unixarea.de (8.15.2/8.14.9) with ESMTPS id x9BE88bX006817 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 11 Oct 2019 16:08:09 +0200 (CEST) (envelope-from guru@unixarea.de) Received: (from guru@localhost) by localhost.my.domain (8.15.2/8.14.9/Submit) id x9BE88hK006816; Fri, 11 Oct 2019 16:08:08 +0200 (CEST) (envelope-from guru@unixarea.de) X-Authentication-Warning: localhost.my.domain: guru set sender to guru@unixarea.de using -f Date: Fri, 11 Oct 2019 16:08:08 +0200 From: Matthias Apitz To: Christoph Moench-Tegeder , pgsql-general@lists.postgresql.org Subject: Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to the server Message-ID: <20191011140808.GA6717@c720-r342378> Reply-To: Matthias Apitz References: <20191004132529.GA2871@c720-r342378> <20191004142932.GA2532@elch.exwg.net> <20191004150749.GB3724@c720-r342378> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="RnlQjJ0d97Da+TV1" Content-Disposition: inline In-Reply-To: <20191004150749.GB3724@c720-r342378> X-Operating-System: FreeBSD 13.0-CURRENT r342378 (amd64) X-message-flag: Mails containing HTML will not be read! Please send only plain text. User-Agent: Mutt/1.11.1 (2018-12-01) X-Con-Id: 51246 X-Con-U: 0-guru X-Originating-IP: 188.174.95.79 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --RnlQjJ0d97Da+TV1 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Christoph, May I come back to the UTF-8 problem, but now for the reading aspect: I connect to the PG server with: $dbh =3D DBI->connect($PGDB, $PGDB_USER, $PGDB_PASS, { pg_utf8_flag =3D> 1, pg_enable_utf8 =3D> 1, AutoCommit =3D> 0, RaiseError =3D> 0, PrintError =3D> 0, } ); and do a SELECT for a column which contains UTF-8 data (I double checked this with SQL and ::bytea): $sth=3D$dbh->prepare( "select d02name from d02ben where d02bnr =3D '00001048313'") or die "parse error\n".$DBI::errstr."\n"; $sth->execute or die "exec error\n".$DBI::errstr."\n"; but when I now fetch the first row with: @row =3D $sth->fetchrow_array; $HexStr =3D unpack("H*", $row[0]); print "HexStr: " . $HexStr . "\n"; print "$row[0]\n"; The resulting column contains ISO data: HexStr: 50e46461676f67697363686520486f6368736368756c65205765696e67617274656= e20202020202020202020202020202020202020202020202020202020202020202020202020= 202020202020202020202020202020202020202020202020202020202020202020202020202= 02020202020202020202020 Pdagogische Hochschule Weingarten = =20 Following the man page of DBD::Pg the attribute pg_enable_utf8 =3D> 1 should ensure that strings are returned from DBI with the UTF-8 flag switched on. The server sends the string in UTF-8 as I can see with strace: =2E.. recvfrom(3, "T\0\0\0 \0\1d02name\0\0\1\313\237\0\3\0\0\4\22\377\377\0\0\0|\= 0\0D\0\0\0\203\0\1\0\0\0yP\303\244dagogische Hochschule Weingarten = = C\0\0\0\rSELECT 1\0Z\0\0\0\5T", 16384, 0, NULL, NULL) =3D 185 write(1, "HexStr: 50e46461676f67697363686520486f6368736368756c65205765696e6= 7617274656e2020202020202020202020202020202020202020202020202020202020202020= 202020202020202020202020202020202020202020202020202020202020202020202020202= 020202020202020202020202020202020\n", 249) =3D 249 write(1, "P\344dagogische Hochschule Weingarten =20 But why it gets translated to ISO? Thanks for your help again. matthias --=20 Matthias Apitz, =E2=9C=89 guru@unixarea.de, http://www.unixarea.de/ +49-176= -38902045 Public GnuPG key: http://www.unixarea.de/key.pub --RnlQjJ0d97Da+TV1 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEXmn7rBYYViyzy/vBR8z35Hb+nREFAl2gjMUACgkQR8z35Hb+ nRFCrQ//eKvWFTVn/5orHKO3iQeZohtsg2A6D9fs+7xnNDTSY5tAMZa8z8HzM4Jp uFVJnCntscU6vsNGnrLvygQHv41UcYWdHauEyqdSkDGLTsM6ifvFuRnxIfFvydqn cY79GMM4zqWC39es8GNAFyyz73B2O8qlnVcyEcQoF4/5HSxyZyYoBfcZwyqM82zn 3uCwPMhp8NJXvPtH6sJy+BvnfBfsYNUx3sSAYZdTI/MX0taY1mGqHwIr/l/9vhHq x1NLt/5bJduke7Qejphm2IX9XSsv2/XTj2tkYEjmjh2stF5zzUVNGbxmRB2eCTk8 QM2rkavE/MYFLlD3y5XZoSSaQ7P3nJRs6m1p9bd80oE5WD9gUGexXd1OHm9aAmwL 0R5pcVdcuEQihzEvQeC9fAuNrIRwKhcdHQyksFDyWGTBdZxwMszTxS+GEeGCyOjB Jg1rH/2tOjm6JDs/w3R5y9RFW//b2VRY8xl86KMCN0HFNRqE3xzCbgG9QAE0jjjN PY8H9cZJe002UiI9J3b1iOsC7bdaU0JQz91p9eF6FdMD6qcixMIl+MhE50EGr/Uk 4IPeBmSjrhqGhOktuHt0opcUIjjrmna2Cf6Vpg9xKZ+BWbsBZUn1LtOizrPeiMNL U2gEwYB32AWlPcyfw0G/Rds+OL6QtVpn1ZBcFPYWVEQMF1bjna4= =P38N -----END PGP SIGNATURE----- --RnlQjJ0d97Da+TV1--