|
| 1 | +-- |
| 2 | +-- Unicode handling |
| 3 | +-- |
| 4 | +CREATE TABLE unicode_test ( |
| 5 | + testvalue text NOT NULL |
| 6 | +); |
| 7 | +CREATE FUNCTION unicode_return() RETURNS text AS E' |
| 8 | +return u"\\x80" |
| 9 | +' LANGUAGE plpythonu; |
| 10 | +CREATE FUNCTION unicode_trigger() RETURNS trigger AS E' |
| 11 | +TD["new"]["testvalue"] = u"\\x80" |
| 12 | +return "MODIFY" |
| 13 | +' LANGUAGE plpythonu; |
| 14 | +CREATE TRIGGER unicode_test_bi BEFORE INSERT ON unicode_test |
| 15 | + FOR EACH ROW EXECUTE PROCEDURE unicode_trigger(); |
| 16 | +CREATE FUNCTION unicode_plan1() RETURNS text AS E' |
| 17 | +plan = plpy.prepare("SELECT $1 AS testvalue", ["text"]) |
| 18 | +rv = plpy.execute(plan, [u"\\x80"], 1) |
| 19 | +return rv[0]["testvalue"] |
| 20 | +' LANGUAGE plpythonu; |
| 21 | +CREATE FUNCTION unicode_plan2() RETURNS text AS E' |
| 22 | +plan = plpy.prepare("SELECT $1 || $2 AS testvalue", ["text", u"text"]) |
| 23 | +rv = plpy.execute(plan, ["foo", "bar"], 1) |
| 24 | +return rv[0]["testvalue"] |
| 25 | +' LANGUAGE plpythonu; |
| 26 | +SELECT unicode_return(); |
| 27 | +ERROR: PL/Python: could not convert Python Unicode object to PostgreSQL server encoding |
| 28 | +DETAIL: <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128) |
| 29 | +CONTEXT: while creating return value |
| 30 | +PL/Python function "unicode_return" |
| 31 | +INSERT INTO unicode_test (testvalue) VALUES ('test'); |
| 32 | +ERROR: PL/Python: could not convert Python Unicode object to PostgreSQL server encoding |
| 33 | +DETAIL: <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128) |
| 34 | +CONTEXT: while modifying trigger row |
| 35 | +PL/Python function "unicode_trigger" |
| 36 | +SELECT * FROM unicode_test; |
| 37 | + testvalue |
| 38 | +----------- |
| 39 | +(0 rows) |
| 40 | + |
| 41 | +SELECT unicode_plan1(); |
| 42 | +WARNING: PL/Python: <class 'plpy.Error'>: unrecognized error in PLy_spi_execute_plan |
| 43 | +CONTEXT: PL/Python function "unicode_plan1" |
| 44 | +ERROR: PL/Python: could not convert Python Unicode object to PostgreSQL server encoding |
| 45 | +DETAIL: <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128) |
| 46 | +CONTEXT: PL/Python function "unicode_plan1" |
| 47 | +SELECT unicode_plan2(); |
| 48 | + unicode_plan2 |
| 49 | +--------------- |
| 50 | + foobar |
| 51 | +(1 row) |
| 52 | + |
0 commit comments