1 -- first some tests of basic functionality
2 CREATE EXTENSION plpython2u;
3 -- really stupid function just to get the module loaded
4 CREATE FUNCTION stupid() RETURNS text AS 'return "zarkon"' LANGUAGE plpythonu;
11 -- check 2/3 versioning
12 CREATE FUNCTION stupidn() RETURNS text AS 'return "zarkon"' LANGUAGE plpython2u;
19 -- test multiple arguments and odd characters in function name
20 CREATE FUNCTION "Argument test #1"(u users, a1 text, a2 text) RETURNS text
22 'keys = list(u.keys())
26 out.append("%s: %s" % (key, u[key]))
27 words = a1 + " " + a2 + " => {" + ", ".join(out) + "}"
30 select "Argument test #1"(users, fname, lname) from users where lname = 'doe' order by 1;
32 -----------------------------------------------------------------------
33 jane doe => {fname: jane, lname: doe, userid: 1, username: j_doe}
34 john doe => {fname: john, lname: doe, userid: 2, username: johnd}
35 willem doe => {fname: willem, lname: doe, userid: 3, username: w_doe}
38 -- check module contents
39 CREATE FUNCTION module_contents() RETURNS SETOF text AS
41 contents = list(filter(lambda x: not x.startswith("__"), dir(plpy)))
44 $$ LANGUAGE plpythonu;
45 select module_contents();
70 CREATE FUNCTION elog_test_basic() RETURNS void
77 plpy.info('info', 37, [1, 2, 3])
79 plpy.warning('warning')
81 $$ LANGUAGE plpythonu;
82 SELECT elog_test_basic();
86 INFO: ('info', 37, [1, 2, 3])
89 ERROR: plpy.Error: error
90 CONTEXT: Traceback (most recent call last):
91 PL/Python function "elog_test_basic", line 10, in <module>
93 PL/Python function "elog_test_basic"