Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1adpQ1-0006CX-SF for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Mar 2016 01:29:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1adpQ1-00047c-1i for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Mar 2016 01:29:37 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1adpPO-0003NP-43 for pgsql-bugs@postgresql.org; Thu, 10 Mar 2016 01:28:58 +0000 Received: from mout.gmx.net ([212.227.15.18]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.84) (envelope-from ) id 1adpPL-0002gq-EO for pgsql-bugs@postgresql.org; Thu, 10 Mar 2016 01:28:56 +0000 Received: from auth2-smtp.messagingengine.com ([66.111.4.228]) by mail.gmx.com (mrgmx002) with ESMTPSA (Nemesis) id 0MFuWk-1ab7z80hle-00Eucl for ; Thu, 10 Mar 2016 02:28:52 +0100 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailauth.nyi.internal (Postfix) with ESMTP id 7F49221ACB for ; Wed, 9 Mar 2016 20:28:50 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Wed, 09 Mar 2016 20:28:50 -0500 X-Sasl-enc: w5kL6ifeMcAeEUipPrjgtOKqh8qSGkIoFGEyCCpbtrdH 1457573330 Received: from [10.0.0.4] (c-73-13-69-21.hsd1.pa.comcast.net [73.13.69.21]) by mail.messagingengine.com (Postfix) with ESMTPA id 45190C0001D; Wed, 9 Mar 2016 20:28:50 -0500 (EST) Subject: Re: Error and wrong lenghth of non-ASCII Unicode string in plpythonu To: Volker Paul , pgsql-bugs@postgresql.org References: <569D27E5.90400@v-paul.de> From: Peter Eisentraut Message-ID: <56E0CDD1.3040708@gmx.net> Date: Wed, 9 Mar 2016 20:28:49 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <569D27E5.90400@v-paul.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:VEGRcZUiv8H7Kfq54JmRTxXDYay1T+OTkIXd9LYp4c5GDoumUQW d5D4AszGswVnhEK/MDhmlTnLGKyWBzdKV30SnzUUtKW0kU5teys0FKUWptSIORXH4JE7pPu qsogh2LePslHBcfq83NJdMwDpw6LEkbc48hO2rvtYcrPhugZbx4nb2DVxHPJE1aUFjW/L2I cFjJtOsPODlMIkPSf3tXg== X-UI-Out-Filterresults: notjunk:1;V01:K0:fFGa6eqiSvY=:lgDrDL8kQtgdCVFqLRBva/ 5xvVX7C112vqH/0dbyF6H9s0IX1pd3kESccMN+Olk/IlGr1N1ZuDdy/hkz3R9E4eJYP2u+tx2 YnU5OQ0UzXZgl31nGIr0SLUDzQLGSR6OHSOR1Oc6sT//L2z18ty2Lt38Isag7j/ByyvsVgGsk laDf9cLVmZa+FixorDJCl1/cmaR4viN7+2aMpKDQfIamlOKvYKXclvYR0B1PXMq4UaQRA1Esa FMnpBgzchNVEbfBCb9hMqOCtFl4mS8xdgnRzGM/2LY35p0tYVwbenXRwp2kYOqsBFzukepxVo f23mwuVgyASL3WjGC9wBvKPUAy4Zun5bHePkgyv+DIqD4JPp6uzqsupTXcJ6qhTvmdd4BNEy9 PUMiHNQmfKMf/i1daJ6s8c6z6Fk4ZVplz6lqeTar4uux+8Q1FEBWjYBboCLGRehf7O9996uwP CSm2B7SKsQJmQ0r+bnSCkXdAG2q4Tssyvok7N3+WWfY2gQkXypqAKmbBGBRqU3DDs40pMxnpB gPCocstmgLJAjA9CYhgu+vLoRSaCAPbCcX2ZL6FaHfkjwLQlQW6pagiMYg9Hgdww4YFCrNN3V uC/+7vLqx5r9Np2o9FwMGZ/vSaYpwomjaLQ3yp61GNpRRrj1ApMu6HSi4czvNB6lKKLzN3uKh NNpRkZowDDVx6mDe8Slr0HMw7thMplnlE0oBWS04N6Vwt09U+QXJEJokWqnbU1cc/UGvhVLMd PgZws2D0qdr2PsuOdPVSC1sG1L5lwHlVNeKSV/prn27T37Vzu9Mwd19sca0yXKxEOfKLLJwI2 2pWV5R2 X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 1/18/16 12:59 PM, Volker Paul wrote: > the following plpythonu function reveals wrong length calculation > and error on accessing single characters in a Unicode string. The problem is that in Python 2, source text must be ASCII. So you need to escape any non-ASCII characters using \x or \u escapes or something else. I've tried patching PL/Python so that it automatically inserts a "coding" declaration per PEP-263, but I haven't gotten that to work yet. Your example works fine with Python 3, which expects UTF-8 source encoding, so maybe that's an option for you. (Although now that I think about it, that might have failure scenarios in other database encodings.) -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs