2 -- Test named and nameless parameters
4 CREATE FUNCTION test_param_names0(integer, integer) RETURNS int AS $$
5 return args[0] + args[1]
7 CREATE FUNCTION test_param_names1(a0 integer, a1 text) RETURNS boolean AS $$
11 $$ LANGUAGE plpythonu;
12 CREATE FUNCTION test_param_names2(u users) RETURNS text AS $$
14 if isinstance(u, dict):
15 # stringify dict the hard way because otherwise the order is implementation-dependent
16 u_keys = list(u.keys())
18 s = '{' + ', '.join([repr(k) + ': ' + repr(u[k]) for k in u_keys]) + '}'
22 $$ LANGUAGE plpythonu;
23 -- use deliberately wrong parameter names
24 CREATE FUNCTION test_param_names3(a0 integer) RETURNS boolean AS $$
28 except NameError as e:
29 assert e.args[0].find("a1") > -1
31 $$ LANGUAGE plpythonu;
32 SELECT test_param_names0(2,7);
38 SELECT test_param_names1(1,'text');
44 SELECT test_param_names2(users) from users;
46 -----------------------------------------------------------------------
47 {'fname': 'jane', 'lname': 'doe', 'userid': 1, 'username': 'j_doe'}
48 {'fname': 'john', 'lname': 'doe', 'userid': 2, 'username': 'johnd'}
49 {'fname': 'willem', 'lname': 'doe', 'userid': 3, 'username': 'w_doe'}
50 {'fname': 'rick', 'lname': 'smith', 'userid': 4, 'username': 'slash'}
53 SELECT test_param_names2(NULL);
59 SELECT test_param_names3(1);