1--
2-- Unicode handling
3--
4-- Note: this test case is known to fail if the database encoding is
5-- EUC_CN, EUC_JP, EUC_KR, or EUC_TW, for lack of any equivalent to
6-- U+00A0 (no-break space) in those encodings.  However, testing with
7-- plain ASCII data would be rather useless, so we must live with that.
8--
9SET client_encoding TO UTF8;
10CREATE TABLE unicode_test (
11	testvalue  text NOT NULL
12);
13CREATE FUNCTION unicode_return() RETURNS text AS E'
14return u"\\xA0"
15' LANGUAGE plpythonu;
16CREATE FUNCTION unicode_trigger() RETURNS trigger AS E'
17TD["new"]["testvalue"] = u"\\xA0"
18return "MODIFY"
19' LANGUAGE plpythonu;
20CREATE TRIGGER unicode_test_bi BEFORE INSERT ON unicode_test
21  FOR EACH ROW EXECUTE PROCEDURE unicode_trigger();
22CREATE FUNCTION unicode_plan1() RETURNS text AS E'
23plan = plpy.prepare("SELECT $1 AS testvalue", ["text"])
24rv = plpy.execute(plan, [u"\\xA0"], 1)
25return rv[0]["testvalue"]
26' LANGUAGE plpythonu;
27CREATE FUNCTION unicode_plan2() RETURNS text AS E'
28plan = plpy.prepare("SELECT $1 || $2 AS testvalue", ["text", u"text"])
29rv = plpy.execute(plan, ["foo", "bar"], 1)
30return rv[0]["testvalue"]
31' LANGUAGE plpythonu;
32SELECT unicode_return();
33 unicode_return
34----------------
35  
36(1 row)
37
38INSERT INTO unicode_test (testvalue) VALUES ('test');
39SELECT * FROM unicode_test;
40 testvalue
41-----------
42  
43(1 row)
44
45SELECT unicode_plan1();
46 unicode_plan1
47---------------
48  
49(1 row)
50
51SELECT unicode_plan2();
52 unicode_plan2
53---------------
54 foobar
55(1 row)
56
57