1 -- first some tests of basic functionality
11 -- check static and global data
25 SELECT global_test_one();
27 --------------------------------------------------------
28 SD: set by global_test_one, GD: set by global_test_one
31 SELECT global_test_two();
33 --------------------------------------------------------
34 SD: set by global_test_two, GD: set by global_test_one
37 -- import python modules
40 NOTICE: ('import socket failed -- No module named foosocket',)
46 SELECT import_succeed();
48 ------------------------
49 succeeded, as expected
52 -- test import and simple argument handling
54 SELECT import_test_one('sha hash of this string');
56 ------------------------------------------
57 a04e23cb9b1a09cd1051a04a7c571aae0f90346c
60 -- test import and tuple argument handling
62 select import_test_two(users) from users where fname = 'willem';
64 -------------------------------------------------------------------
65 sha hash of willemdoe is 3cde6b574953b0ca937b4d76ebc40d534d910759
68 -- test multiple arguments
70 select argument_test_one(users, fname, lname) from users where lname = 'doe' order by 1;
72 -----------------------------------------------------------------------
73 jane doe => {fname: jane, lname: doe, userid: 1, username: j_doe}
74 john doe => {fname: john, lname: doe, userid: 2, username: johnd}
75 willem doe => {fname: willem, lname: doe, userid: 3, username: w_doe}
78 -- spi and nested calls
80 select nested_call_one('pass this along');
82 -----------------------------------------------------------------
83 {'nested_call_two': "{'nested_call_three': 'pass this along'}"}
86 select spi_prepared_plan_test_one('doe');
87 spi_prepared_plan_test_one
88 ----------------------------
92 select spi_prepared_plan_test_one('smith');
93 spi_prepared_plan_test_one
94 ----------------------------
98 select spi_prepared_plan_test_nested('smith');
99 spi_prepared_plan_test_nested
100 -------------------------------
104 -- quick peek at the table
107 fname | lname | username | userid
108 --------+-------+----------+--------
109 jane | doe | j_doe | 1
110 john | doe | johnd | 2
111 willem | doe | w_doe | 3
112 rick | smith | slash | 4
117 UPDATE users SET fname = 'william' WHERE fname = 'willem';
118 -- should modify william to willem and create username
120 INSERT INTO users (fname, lname) VALUES ('william', 'smith');
121 INSERT INTO users (fname, lname, username) VALUES ('charles', 'darwin', 'beagle');
123 fname | lname | username | userid
124 ---------+--------+----------+--------
125 jane | doe | j_doe | 1
126 john | doe | johnd | 2
127 willem | doe | w_doe | 3
128 rick | smith | slash | 4
129 willem | smith | w_smith | 5
130 charles | darwin | beagle | 6
133 SELECT join_sequences(sequences) FROM sequences;
144 SELECT join_sequences(sequences) FROM sequences
145 WHERE join_sequences(sequences) ~* '^A';
156 SELECT join_sequences(sequences) FROM sequences
157 WHERE join_sequences(sequences) ~* '^B';
165 -- Check Universal Newline Support
179 SELECT newline_crlf();
185 -- Tests for functions returning void
186 SELECT test_void_func1(), test_void_func1() IS NULL AS "is null";
187 test_void_func1 | is null
188 -----------------+---------
192 SELECT test_void_func2(); -- should fail
193 ERROR: invalid return value from plpython function
194 DETAIL: Functions returning type "void" must return None.
195 SELECT test_return_none(), test_return_none() IS NULL AS "is null";
196 test_return_none | is null
197 ------------------+---------
201 -- Test for functions with named parameters
202 SELECT test_param_names1(1,'text');
208 SELECT test_param_names2(users) from users;
210 ----------------------------------------------------------------------------
211 {'lname': 'doe', 'username': 'j_doe', 'userid': 1, 'fname': 'jane'}
212 {'lname': 'doe', 'username': 'johnd', 'userid': 2, 'fname': 'john'}
213 {'lname': 'doe', 'username': 'w_doe', 'userid': 3, 'fname': 'willem'}
214 {'lname': 'smith', 'username': 'slash', 'userid': 4, 'fname': 'rick'}
215 {'lname': 'smith', 'username': 'w_smith', 'userid': 5, 'fname': 'willem'}
216 {'lname': 'darwin', 'username': 'beagle', 'userid': 6, 'fname': 'charles'}
219 SELECT test_param_names3(1);
225 -- Test set returning functions
226 SELECT test_setof_as_list(0, 'list');
231 SELECT test_setof_as_list(1, 'list');
237 SELECT test_setof_as_list(2, 'list');
244 SELECT test_setof_as_list(2, null);
251 SELECT test_setof_as_tuple(0, 'tuple');
253 ---------------------
256 SELECT test_setof_as_tuple(1, 'tuple');
258 ---------------------
262 SELECT test_setof_as_tuple(2, 'tuple');
264 ---------------------
269 SELECT test_setof_as_tuple(2, null);
271 ---------------------
276 SELECT test_setof_as_iterator(0, 'list');
277 test_setof_as_iterator
278 ------------------------
281 SELECT test_setof_as_iterator(1, 'list');
282 test_setof_as_iterator
283 ------------------------
287 SELECT test_setof_as_iterator(2, 'list');
288 test_setof_as_iterator
289 ------------------------
294 SELECT test_setof_as_iterator(2, null);
295 test_setof_as_iterator
296 ------------------------
301 -- Test tuple returning functions
302 SELECT * FROM test_table_record_as('dict', null, null, false);
308 SELECT * FROM test_table_record_as('dict', 'one', null, false);
314 SELECT * FROM test_table_record_as('dict', null, 2, false);
320 SELECT * FROM test_table_record_as('dict', 'three', 3, false);
326 SELECT * FROM test_table_record_as('dict', null, null, true);
332 SELECT * FROM test_table_record_as('tuple', null, null, false);
338 SELECT * FROM test_table_record_as('tuple', 'one', null, false);
344 SELECT * FROM test_table_record_as('tuple', null, 2, false);
350 SELECT * FROM test_table_record_as('tuple', 'three', 3, false);
356 SELECT * FROM test_table_record_as('tuple', null, null, true);
362 SELECT * FROM test_table_record_as('list', null, null, false);
368 SELECT * FROM test_table_record_as('list', 'one', null, false);
374 SELECT * FROM test_table_record_as('list', null, 2, false);
380 SELECT * FROM test_table_record_as('list', 'three', 3, false);
386 SELECT * FROM test_table_record_as('list', null, null, true);
392 SELECT * FROM test_table_record_as('obj', null, null, false);
398 SELECT * FROM test_table_record_as('obj', 'one', null, false);
404 SELECT * FROM test_table_record_as('obj', null, 2, false);
410 SELECT * FROM test_table_record_as('obj', 'three', 3, false);
416 SELECT * FROM test_table_record_as('obj', null, null, true);
422 SELECT * FROM test_type_record_as('dict', null, null, false);
428 SELECT * FROM test_type_record_as('dict', 'one', null, false);
434 SELECT * FROM test_type_record_as('dict', null, 2, false);
440 SELECT * FROM test_type_record_as('dict', 'three', 3, false);
446 SELECT * FROM test_type_record_as('dict', null, null, true);
452 SELECT * FROM test_type_record_as('tuple', null, null, false);
458 SELECT * FROM test_type_record_as('tuple', 'one', null, false);
464 SELECT * FROM test_type_record_as('tuple', null, 2, false);
470 SELECT * FROM test_type_record_as('tuple', 'three', 3, false);
476 SELECT * FROM test_type_record_as('tuple', null, null, true);
482 SELECT * FROM test_type_record_as('list', null, null, false);
488 SELECT * FROM test_type_record_as('list', 'one', null, false);
494 SELECT * FROM test_type_record_as('list', null, 2, false);
500 SELECT * FROM test_type_record_as('list', 'three', 3, false);
506 SELECT * FROM test_type_record_as('list', null, null, true);
512 SELECT * FROM test_type_record_as('obj', null, null, false);
518 SELECT * FROM test_type_record_as('obj', 'one', null, false);
524 SELECT * FROM test_type_record_as('obj', null, 2, false);
530 SELECT * FROM test_type_record_as('obj', 'three', 3, false);
536 SELECT * FROM test_type_record_as('obj', null, null, true);
542 SELECT * FROM test_in_out_params('test_in');
548 -- this doesn't work yet :-(
549 SELECT * FROM test_in_out_params_multi('test_in');
550 ERROR: plpython functions cannot return type record
551 SELECT * FROM test_inout_params('test_in');