1-- first some tests of basic functionality
2CREATE EXTENSION plpython2u;
3-- really stupid function just to get the module loaded
4CREATE FUNCTION stupid() RETURNS text AS 'return "zarkon"' LANGUAGE plpythonu;
5select stupid();
6 stupid
7--------
8 zarkon
9(1 row)
10
11-- check 2/3 versioning
12CREATE FUNCTION stupidn() RETURNS text AS 'return "zarkon"' LANGUAGE plpython2u;
13select stupidn();
14 stupidn
15---------
16 zarkon
17(1 row)
18
19-- test multiple arguments and odd characters in function name
20CREATE FUNCTION "Argument test #1"(u users, a1 text, a2 text) RETURNS text
21	AS
22'keys = list(u.keys())
23keys.sort()
24out = []
25for key in keys:
26    out.append("%s: %s" % (key, u[key]))
27words = a1 + " " + a2 + " => {" + ", ".join(out) + "}"
28return words'
29	LANGUAGE plpythonu;
30select "Argument test #1"(users, fname, lname) from users where lname = 'doe' order by 1;
31                           Argument test #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}
36(3 rows)
37
38-- check module contents
39CREATE FUNCTION module_contents() RETURNS SETOF text AS
40$$
41contents = list(filter(lambda x: not x.startswith("__"), dir(plpy)))
42contents.sort()
43return contents
44$$ LANGUAGE plpythonu;
45select module_contents();
46 module_contents
47-----------------
48 Error
49 Fatal
50 SPIError
51 commit
52 cursor
53 debug
54 error
55 execute
56 fatal
57 info
58 log
59 notice
60 prepare
61 quote_ident
62 quote_literal
63 quote_nullable
64 rollback
65 spiexceptions
66 subtransaction
67 warning
68(20 rows)
69
70CREATE FUNCTION elog_test_basic() RETURNS void
71AS $$
72plpy.debug('debug')
73plpy.log('log')
74plpy.info('info')
75plpy.info(37)
76plpy.info()
77plpy.info('info', 37, [1, 2, 3])
78plpy.notice('notice')
79plpy.warning('warning')
80plpy.error('error')
81$$ LANGUAGE plpythonu;
82SELECT elog_test_basic();
83INFO:  info
84INFO:  37
85INFO:  ()
86INFO:  ('info', 37, [1, 2, 3])
87NOTICE:  notice
88WARNING:  warning
89ERROR:  plpy.Error: error
90CONTEXT:  Traceback (most recent call last):
91  PL/Python function "elog_test_basic", line 10, in <module>
92    plpy.error('error')
93PL/Python function "elog_test_basic"
94