Re: can't load plpython

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Euler Taveira de Oliveira <euler(at)timbira(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: can't load plpython
Date: 2009-04-03 18:00:36
Message-ID: 20090403180036.GH23023@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:

> Alvaro's example now gives me this on Fedora 10:
>
> ERROR: PL/Python: PL/Python function "unaccent" failed
> DETAIL: <type 'exceptions.TypeError'>: normalize() argument 2 must be unicode, not str
>
> which is the same as it did in 8.3. I do not know if that's a bug
> or expected (making the database encoding be utf8 doesn't help).

Apparently the problem is that "str" is a different type in Python than
"unicode". I could get it to work this way:

create or replace function unaccent(text) returns text language plpythonu as $$
import unicodedata
rv = plpy.execute("select setting from pg_settings where name = 'server_encoding'");
encoding = rv[0]["setting"]
s = args[0].decode(encoding)
s = unicodedata.normalize("NFKD", s)
s = ''.join(c for c in s if ord(c) < 127)
return s
$$;

> Alvaro, would you see if it still crashes for you on Debian?
> If so there's some other issue with python 2.5.4 ...

It works for me now. Thanks to Euler for tracking the Python problem
down and to you for the commit!

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Lawrence, Ramon 2009-04-03 18:44:50 Re: a few crazy ideas about hash joins
Previous Message Kevin Grittner 2009-04-03 17:23:26 Re: a few crazy ideas about hash joins