Re: can't load plpython - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: can't load plpython
Date
Msg-id 20090403180036.GH23023@alvh.no-ip.org
Whole thread Raw
In response to Re: can't load plpython  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: can't load plpython  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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


pgsql-hackers by date:

Previous
From: "Kevin Grittner"
Date:
Subject: Re: a few crazy ideas about hash joins
Next
From: "Lawrence, Ramon"
Date:
Subject: Re: a few crazy ideas about hash joins