Re: Error and wrong lenghth of non-ASCII Unicode string in plpythonu

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Volker Paul <volker(dot)paul(at)v-paul(dot)de>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: Error and wrong lenghth of non-ASCII Unicode string in plpythonu
Date: 2016-03-10 01:28:49
Message-ID: 56E0CDD1.3040708@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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.)

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message 张文升 2016-03-10 02:41:14 Re: gram.y comment issue
Previous Message Breen Hagan 2016-03-09 22:44:18 Re: BUG #13755: pgwin32_is_service not checking if SECURITY_SERVICE_SID is disabled