2 -- Test data type behavior
7 CREATE FUNCTION test_type_conversion_bool(x bool) RETURNS bool AS $$
10 $$ LANGUAGE plpython3u;
11 SELECT * FROM test_type_conversion_bool(true);
12 INFO: (True, <class 'bool'>)
13 CONTEXT: PL/Python function "test_type_conversion_bool"
14 test_type_conversion_bool
15 ---------------------------
19 SELECT * FROM test_type_conversion_bool(false);
20 INFO: (False, <class 'bool'>)
21 CONTEXT: PL/Python function "test_type_conversion_bool"
22 test_type_conversion_bool
23 ---------------------------
27 SELECT * FROM test_type_conversion_bool(null);
28 INFO: (None, <class 'NoneType'>)
29 CONTEXT: PL/Python function "test_type_conversion_bool"
30 test_type_conversion_bool
31 ---------------------------
35 -- test various other ways to express Booleans in Python
36 CREATE FUNCTION test_type_conversion_bool_other(n int) RETURNS bool AS $$
46 ret = 'fa' # true in Python, false in PostgreSQL
52 plpy.info(ret, not not ret)
54 $$ LANGUAGE plpython3u;
55 SELECT * FROM test_type_conversion_bool_other(0);
57 CONTEXT: PL/Python function "test_type_conversion_bool_other"
58 test_type_conversion_bool_other
59 ---------------------------------
63 SELECT * FROM test_type_conversion_bool_other(1);
65 CONTEXT: PL/Python function "test_type_conversion_bool_other"
66 test_type_conversion_bool_other
67 ---------------------------------
71 SELECT * FROM test_type_conversion_bool_other(2);
73 CONTEXT: PL/Python function "test_type_conversion_bool_other"
74 test_type_conversion_bool_other
75 ---------------------------------
79 SELECT * FROM test_type_conversion_bool_other(3);
81 CONTEXT: PL/Python function "test_type_conversion_bool_other"
82 test_type_conversion_bool_other
83 ---------------------------------
87 SELECT * FROM test_type_conversion_bool_other(4);
89 CONTEXT: PL/Python function "test_type_conversion_bool_other"
90 test_type_conversion_bool_other
91 ---------------------------------
95 SELECT * FROM test_type_conversion_bool_other(5);
97 CONTEXT: PL/Python function "test_type_conversion_bool_other"
98 test_type_conversion_bool_other
99 ---------------------------------
103 CREATE FUNCTION test_type_conversion_char(x char) RETURNS char AS $$
104 plpy.info(x, type(x))
106 $$ LANGUAGE plpython3u;
107 SELECT * FROM test_type_conversion_char('a');
108 INFO: ('a', <class 'str'>)
109 CONTEXT: PL/Python function "test_type_conversion_char"
110 test_type_conversion_char
111 ---------------------------
115 SELECT * FROM test_type_conversion_char(null);
116 INFO: (None, <class 'NoneType'>)
117 CONTEXT: PL/Python function "test_type_conversion_char"
118 test_type_conversion_char
119 ---------------------------
123 CREATE FUNCTION test_type_conversion_int2(x int2) RETURNS int2 AS $$
124 plpy.info(x, type(x))
126 $$ LANGUAGE plpython3u;
127 SELECT * FROM test_type_conversion_int2(100::int2);
128 INFO: (100, <class 'int'>)
129 CONTEXT: PL/Python function "test_type_conversion_int2"
130 test_type_conversion_int2
131 ---------------------------
135 SELECT * FROM test_type_conversion_int2(-100::int2);
136 INFO: (-100, <class 'int'>)
137 CONTEXT: PL/Python function "test_type_conversion_int2"
138 test_type_conversion_int2
139 ---------------------------
143 SELECT * FROM test_type_conversion_int2(null);
144 INFO: (None, <class 'NoneType'>)
145 CONTEXT: PL/Python function "test_type_conversion_int2"
146 test_type_conversion_int2
147 ---------------------------
151 CREATE FUNCTION test_type_conversion_int4(x int4) RETURNS int4 AS $$
152 plpy.info(x, type(x))
154 $$ LANGUAGE plpython3u;
155 SELECT * FROM test_type_conversion_int4(100);
156 INFO: (100, <class 'int'>)
157 CONTEXT: PL/Python function "test_type_conversion_int4"
158 test_type_conversion_int4
159 ---------------------------
163 SELECT * FROM test_type_conversion_int4(-100);
164 INFO: (-100, <class 'int'>)
165 CONTEXT: PL/Python function "test_type_conversion_int4"
166 test_type_conversion_int4
167 ---------------------------
171 SELECT * FROM test_type_conversion_int4(null);
172 INFO: (None, <class 'NoneType'>)
173 CONTEXT: PL/Python function "test_type_conversion_int4"
174 test_type_conversion_int4
175 ---------------------------
179 CREATE FUNCTION test_type_conversion_int8(x int8) RETURNS int8 AS $$
180 plpy.info(x, type(x))
182 $$ LANGUAGE plpython3u;
183 SELECT * FROM test_type_conversion_int8(100);
184 INFO: (100, <class 'int'>)
185 CONTEXT: PL/Python function "test_type_conversion_int8"
186 test_type_conversion_int8
187 ---------------------------
191 SELECT * FROM test_type_conversion_int8(-100);
192 INFO: (-100, <class 'int'>)
193 CONTEXT: PL/Python function "test_type_conversion_int8"
194 test_type_conversion_int8
195 ---------------------------
199 SELECT * FROM test_type_conversion_int8(5000000000);
200 INFO: (5000000000, <class 'int'>)
201 CONTEXT: PL/Python function "test_type_conversion_int8"
202 test_type_conversion_int8
203 ---------------------------
207 SELECT * FROM test_type_conversion_int8(null);
208 INFO: (None, <class 'NoneType'>)
209 CONTEXT: PL/Python function "test_type_conversion_int8"
210 test_type_conversion_int8
211 ---------------------------
215 CREATE FUNCTION test_type_conversion_numeric(x numeric) RETURNS numeric AS $$
216 # print just the class name, not the type, to avoid differences
217 # between decimal and cdecimal
218 plpy.info(x, x.__class__.__name__)
220 $$ LANGUAGE plpython3u;
221 SELECT * FROM test_type_conversion_numeric(100);
222 INFO: (Decimal('100'), 'Decimal')
223 CONTEXT: PL/Python function "test_type_conversion_numeric"
224 test_type_conversion_numeric
225 ------------------------------
229 SELECT * FROM test_type_conversion_numeric(-100);
230 INFO: (Decimal('-100'), 'Decimal')
231 CONTEXT: PL/Python function "test_type_conversion_numeric"
232 test_type_conversion_numeric
233 ------------------------------
237 SELECT * FROM test_type_conversion_numeric(100.0);
238 INFO: (Decimal('100.0'), 'Decimal')
239 CONTEXT: PL/Python function "test_type_conversion_numeric"
240 test_type_conversion_numeric
241 ------------------------------
245 SELECT * FROM test_type_conversion_numeric(100.00);
246 INFO: (Decimal('100.00'), 'Decimal')
247 CONTEXT: PL/Python function "test_type_conversion_numeric"
248 test_type_conversion_numeric
249 ------------------------------
253 SELECT * FROM test_type_conversion_numeric(5000000000.5);
254 INFO: (Decimal('5000000000.5'), 'Decimal')
255 CONTEXT: PL/Python function "test_type_conversion_numeric"
256 test_type_conversion_numeric
257 ------------------------------
261 SELECT * FROM test_type_conversion_numeric(1234567890.0987654321);
262 INFO: (Decimal('1234567890.0987654321'), 'Decimal')
263 CONTEXT: PL/Python function "test_type_conversion_numeric"
264 test_type_conversion_numeric
265 ------------------------------
266 1234567890.0987654321
269 SELECT * FROM test_type_conversion_numeric(-1234567890.0987654321);
270 INFO: (Decimal('-1234567890.0987654321'), 'Decimal')
271 CONTEXT: PL/Python function "test_type_conversion_numeric"
272 test_type_conversion_numeric
273 ------------------------------
274 -1234567890.0987654321
277 SELECT * FROM test_type_conversion_numeric(null);
278 INFO: (None, 'NoneType')
279 CONTEXT: PL/Python function "test_type_conversion_numeric"
280 test_type_conversion_numeric
281 ------------------------------
285 CREATE FUNCTION test_type_conversion_float4(x float4) RETURNS float4 AS $$
286 plpy.info(x, type(x))
288 $$ LANGUAGE plpython3u;
289 SELECT * FROM test_type_conversion_float4(100);
290 INFO: (100.0, <class 'float'>)
291 CONTEXT: PL/Python function "test_type_conversion_float4"
292 test_type_conversion_float4
293 -----------------------------
297 SELECT * FROM test_type_conversion_float4(-100);
298 INFO: (-100.0, <class 'float'>)
299 CONTEXT: PL/Python function "test_type_conversion_float4"
300 test_type_conversion_float4
301 -----------------------------
305 SELECT * FROM test_type_conversion_float4(5000.5);
306 INFO: (5000.5, <class 'float'>)
307 CONTEXT: PL/Python function "test_type_conversion_float4"
308 test_type_conversion_float4
309 -----------------------------
313 SELECT * FROM test_type_conversion_float4(null);
314 INFO: (None, <class 'NoneType'>)
315 CONTEXT: PL/Python function "test_type_conversion_float4"
316 test_type_conversion_float4
317 -----------------------------
321 CREATE FUNCTION test_type_conversion_float8(x float8) RETURNS float8 AS $$
322 plpy.info(x, type(x))
324 $$ LANGUAGE plpython3u;
325 SELECT * FROM test_type_conversion_float8(100);
326 INFO: (100.0, <class 'float'>)
327 CONTEXT: PL/Python function "test_type_conversion_float8"
328 test_type_conversion_float8
329 -----------------------------
333 SELECT * FROM test_type_conversion_float8(-100);
334 INFO: (-100.0, <class 'float'>)
335 CONTEXT: PL/Python function "test_type_conversion_float8"
336 test_type_conversion_float8
337 -----------------------------
341 SELECT * FROM test_type_conversion_float8(5000000000.5);
342 INFO: (5000000000.5, <class 'float'>)
343 CONTEXT: PL/Python function "test_type_conversion_float8"
344 test_type_conversion_float8
345 -----------------------------
349 SELECT * FROM test_type_conversion_float8(null);
350 INFO: (None, <class 'NoneType'>)
351 CONTEXT: PL/Python function "test_type_conversion_float8"
352 test_type_conversion_float8
353 -----------------------------
357 CREATE FUNCTION test_type_conversion_oid(x oid) RETURNS oid AS $$
358 plpy.info(x, type(x))
360 $$ LANGUAGE plpython3u;
361 SELECT * FROM test_type_conversion_oid(100);
362 INFO: (100, <class 'int'>)
363 CONTEXT: PL/Python function "test_type_conversion_oid"
364 test_type_conversion_oid
365 --------------------------
369 SELECT * FROM test_type_conversion_oid(2147483649);
370 INFO: (2147483649, <class 'int'>)
371 CONTEXT: PL/Python function "test_type_conversion_oid"
372 test_type_conversion_oid
373 --------------------------
377 SELECT * FROM test_type_conversion_oid(null);
378 INFO: (None, <class 'NoneType'>)
379 CONTEXT: PL/Python function "test_type_conversion_oid"
380 test_type_conversion_oid
381 --------------------------
385 CREATE FUNCTION test_type_conversion_text(x text) RETURNS text AS $$
386 plpy.info(x, type(x))
388 $$ LANGUAGE plpython3u;
389 SELECT * FROM test_type_conversion_text('hello world');
390 INFO: ('hello world', <class 'str'>)
391 CONTEXT: PL/Python function "test_type_conversion_text"
392 test_type_conversion_text
393 ---------------------------
397 SELECT * FROM test_type_conversion_text(null);
398 INFO: (None, <class 'NoneType'>)
399 CONTEXT: PL/Python function "test_type_conversion_text"
400 test_type_conversion_text
401 ---------------------------
405 CREATE FUNCTION test_type_conversion_bytea(x bytea) RETURNS bytea AS $$
406 plpy.info(x, type(x))
408 $$ LANGUAGE plpython3u;
409 SELECT * FROM test_type_conversion_bytea('hello world');
410 INFO: (b'hello world', <class 'bytes'>)
411 CONTEXT: PL/Python function "test_type_conversion_bytea"
412 test_type_conversion_bytea
413 ----------------------------
414 \x68656c6c6f20776f726c64
417 SELECT * FROM test_type_conversion_bytea(E'null\\000byte');
418 INFO: (b'null\x00byte', <class 'bytes'>)
419 CONTEXT: PL/Python function "test_type_conversion_bytea"
420 test_type_conversion_bytea
421 ----------------------------
425 SELECT * FROM test_type_conversion_bytea(null);
426 INFO: (None, <class 'NoneType'>)
427 CONTEXT: PL/Python function "test_type_conversion_bytea"
428 test_type_conversion_bytea
429 ----------------------------
433 CREATE FUNCTION test_type_marshal() RETURNS bytea AS $$
435 return marshal.dumps('hello world')
436 $$ LANGUAGE plpython3u;
437 CREATE FUNCTION test_type_unmarshal(x bytea) RETURNS text AS $$
440 return marshal.loads(x)
441 except ValueError as e:
442 return 'FAILED: ' + str(e)
443 $$ LANGUAGE plpython3u;
444 SELECT test_type_unmarshal(x) FROM test_type_marshal() x;
446 ---------------------
453 CREATE DOMAIN booltrue AS bool CHECK (VALUE IS TRUE OR VALUE IS NULL);
454 CREATE FUNCTION test_type_conversion_booltrue(x booltrue, y bool) RETURNS booltrue AS $$
456 $$ LANGUAGE plpython3u;
457 SELECT * FROM test_type_conversion_booltrue(true, true);
458 test_type_conversion_booltrue
459 -------------------------------
463 SELECT * FROM test_type_conversion_booltrue(false, true);
464 ERROR: value for domain booltrue violates check constraint "booltrue_check"
465 SELECT * FROM test_type_conversion_booltrue(true, false);
466 ERROR: value for domain booltrue violates check constraint "booltrue_check"
467 CONTEXT: while creating return value
468 PL/Python function "test_type_conversion_booltrue"
469 CREATE DOMAIN uint2 AS int2 CHECK (VALUE >= 0);
470 CREATE FUNCTION test_type_conversion_uint2(x uint2, y int) RETURNS uint2 AS $$
471 plpy.info(x, type(x))
473 $$ LANGUAGE plpython3u;
474 SELECT * FROM test_type_conversion_uint2(100::uint2, 50);
475 INFO: (100, <class 'int'>)
476 CONTEXT: PL/Python function "test_type_conversion_uint2"
477 test_type_conversion_uint2
478 ----------------------------
482 SELECT * FROM test_type_conversion_uint2(100::uint2, -50);
483 INFO: (100, <class 'int'>)
484 CONTEXT: PL/Python function "test_type_conversion_uint2"
485 ERROR: value for domain uint2 violates check constraint "uint2_check"
486 CONTEXT: while creating return value
487 PL/Python function "test_type_conversion_uint2"
488 SELECT * FROM test_type_conversion_uint2(null, 1);
489 INFO: (None, <class 'NoneType'>)
490 CONTEXT: PL/Python function "test_type_conversion_uint2"
491 test_type_conversion_uint2
492 ----------------------------
496 CREATE DOMAIN nnint AS int CHECK (VALUE IS NOT NULL);
497 CREATE FUNCTION test_type_conversion_nnint(x nnint, y int) RETURNS nnint AS $$
499 $$ LANGUAGE plpython3u;
500 SELECT * FROM test_type_conversion_nnint(10, 20);
501 test_type_conversion_nnint
502 ----------------------------
506 SELECT * FROM test_type_conversion_nnint(null, 20);
507 ERROR: value for domain nnint violates check constraint "nnint_check"
508 SELECT * FROM test_type_conversion_nnint(10, null);
509 ERROR: value for domain nnint violates check constraint "nnint_check"
510 CONTEXT: while creating return value
511 PL/Python function "test_type_conversion_nnint"
512 CREATE DOMAIN bytea10 AS bytea CHECK (octet_length(VALUE) = 10 AND VALUE IS NOT NULL);
513 CREATE FUNCTION test_type_conversion_bytea10(x bytea10, y bytea) RETURNS bytea10 AS $$
514 plpy.info(x, type(x))
516 $$ LANGUAGE plpython3u;
517 SELECT * FROM test_type_conversion_bytea10('hello wold', 'hello wold');
518 INFO: (b'hello wold', <class 'bytes'>)
519 CONTEXT: PL/Python function "test_type_conversion_bytea10"
520 test_type_conversion_bytea10
521 ------------------------------
522 \x68656c6c6f20776f6c64
525 SELECT * FROM test_type_conversion_bytea10('hello world', 'hello wold');
526 ERROR: value for domain bytea10 violates check constraint "bytea10_check"
527 SELECT * FROM test_type_conversion_bytea10('hello word', 'hello world');
528 INFO: (b'hello word', <class 'bytes'>)
529 CONTEXT: PL/Python function "test_type_conversion_bytea10"
530 ERROR: value for domain bytea10 violates check constraint "bytea10_check"
531 CONTEXT: while creating return value
532 PL/Python function "test_type_conversion_bytea10"
533 SELECT * FROM test_type_conversion_bytea10(null, 'hello word');
534 ERROR: value for domain bytea10 violates check constraint "bytea10_check"
535 SELECT * FROM test_type_conversion_bytea10('hello word', null);
536 INFO: (b'hello word', <class 'bytes'>)
537 CONTEXT: PL/Python function "test_type_conversion_bytea10"
538 ERROR: value for domain bytea10 violates check constraint "bytea10_check"
539 CONTEXT: while creating return value
540 PL/Python function "test_type_conversion_bytea10"
544 CREATE FUNCTION test_type_conversion_array_int4(x int4[]) RETURNS int4[] AS $$
545 plpy.info(x, type(x))
547 $$ LANGUAGE plpython3u;
548 SELECT * FROM test_type_conversion_array_int4(ARRAY[0, 100]);
549 INFO: ([0, 100], <class 'list'>)
550 CONTEXT: PL/Python function "test_type_conversion_array_int4"
551 test_type_conversion_array_int4
552 ---------------------------------
556 SELECT * FROM test_type_conversion_array_int4(ARRAY[0,-100,55]);
557 INFO: ([0, -100, 55], <class 'list'>)
558 CONTEXT: PL/Python function "test_type_conversion_array_int4"
559 test_type_conversion_array_int4
560 ---------------------------------
564 SELECT * FROM test_type_conversion_array_int4(ARRAY[NULL,1]);
565 INFO: ([None, 1], <class 'list'>)
566 CONTEXT: PL/Python function "test_type_conversion_array_int4"
567 test_type_conversion_array_int4
568 ---------------------------------
572 SELECT * FROM test_type_conversion_array_int4(ARRAY[]::integer[]);
573 INFO: ([], <class 'list'>)
574 CONTEXT: PL/Python function "test_type_conversion_array_int4"
575 test_type_conversion_array_int4
576 ---------------------------------
580 SELECT * FROM test_type_conversion_array_int4(NULL);
581 INFO: (None, <class 'NoneType'>)
582 CONTEXT: PL/Python function "test_type_conversion_array_int4"
583 test_type_conversion_array_int4
584 ---------------------------------
588 SELECT * FROM test_type_conversion_array_int4(ARRAY[[1,2,3],[4,5,6]]);
589 ERROR: cannot convert multidimensional array to Python list
590 DETAIL: PL/Python only supports one-dimensional arrays.
591 CONTEXT: PL/Python function "test_type_conversion_array_int4"
592 CREATE FUNCTION test_type_conversion_array_text(x text[]) RETURNS text[] AS $$
593 plpy.info(x, type(x))
595 $$ LANGUAGE plpython3u;
596 SELECT * FROM test_type_conversion_array_text(ARRAY['foo', 'bar']);
597 INFO: (['foo', 'bar'], <class 'list'>)
598 CONTEXT: PL/Python function "test_type_conversion_array_text"
599 test_type_conversion_array_text
600 ---------------------------------
604 CREATE FUNCTION test_type_conversion_array_bytea(x bytea[]) RETURNS bytea[] AS $$
605 plpy.info(x, type(x))
607 $$ LANGUAGE plpython3u;
608 SELECT * FROM test_type_conversion_array_bytea(ARRAY[E'\\xdeadbeef'::bytea, NULL]);
609 INFO: ([b'\xde\xad\xbe\xef', None], <class 'list'>)
610 CONTEXT: PL/Python function "test_type_conversion_array_bytea"
611 test_type_conversion_array_bytea
612 ----------------------------------
616 CREATE FUNCTION test_type_conversion_array_mixed1() RETURNS text[] AS $$
618 $$ LANGUAGE plpython3u;
619 SELECT * FROM test_type_conversion_array_mixed1();
620 test_type_conversion_array_mixed1
621 -----------------------------------
625 CREATE FUNCTION test_type_conversion_array_mixed2() RETURNS int[] AS $$
627 $$ LANGUAGE plpython3u;
628 SELECT * FROM test_type_conversion_array_mixed2();
629 ERROR: invalid input syntax for integer: "abc"
630 CONTEXT: while creating return value
631 PL/Python function "test_type_conversion_array_mixed2"
632 CREATE FUNCTION test_type_conversion_array_record() RETURNS type_record[] AS $$
634 $$ LANGUAGE plpython3u;
635 ERROR: PL/Python functions cannot return type type_record[]
636 DETAIL: PL/Python does not support conversion to arrays of row types.
637 SELECT * FROM test_type_conversion_array_record();
638 ERROR: function test_type_conversion_array_record() does not exist
639 LINE 1: SELECT * FROM test_type_conversion_array_record();
641 HINT: No function matches the given name and argument types. You might need to add explicit type casts.
642 CREATE FUNCTION test_type_conversion_array_string() RETURNS text[] AS $$
644 $$ LANGUAGE plpython3u;
645 SELECT * FROM test_type_conversion_array_string();
646 test_type_conversion_array_string
647 -----------------------------------
651 CREATE FUNCTION test_type_conversion_array_tuple() RETURNS text[] AS $$
652 return ('abc', 'def')
653 $$ LANGUAGE plpython3u;
654 SELECT * FROM test_type_conversion_array_tuple();
655 test_type_conversion_array_tuple
656 ----------------------------------
660 CREATE FUNCTION test_type_conversion_array_error() RETURNS int[] AS $$
662 $$ LANGUAGE plpython3u;
663 SELECT * FROM test_type_conversion_array_error();
664 ERROR: return value of function with array return type is not a Python sequence
665 CONTEXT: while creating return value
666 PL/Python function "test_type_conversion_array_error"
670 CREATE TABLE employee (
675 INSERT INTO employee VALUES ('John', 100, 10), ('Mary', 200, 10);
676 CREATE OR REPLACE FUNCTION test_composite_table_input(e employee) RETURNS integer AS $$
677 return e['basesalary'] + e['bonus']
678 $$ LANGUAGE plpython3u;
679 SELECT name, test_composite_table_input(employee.*) FROM employee;
680 name | test_composite_table_input
681 ------+----------------------------
686 ALTER TABLE employee DROP bonus;
687 SELECT name, test_composite_table_input(employee.*) FROM employee;
688 ERROR: KeyError: 'bonus'
689 CONTEXT: Traceback (most recent call last):
690 PL/Python function "test_composite_table_input", line 2, in <module>
691 return e['basesalary'] + e['bonus']
692 PL/Python function "test_composite_table_input"
693 ALTER TABLE employee ADD bonus integer;
694 UPDATE employee SET bonus = 10;
695 SELECT name, test_composite_table_input(employee.*) FROM employee;
696 name | test_composite_table_input
697 ------+----------------------------
702 CREATE TYPE named_pair AS (
706 CREATE OR REPLACE FUNCTION test_composite_type_input(p named_pair) RETURNS integer AS $$
707 return sum(p.values())
708 $$ LANGUAGE plpython3u;
709 SELECT test_composite_type_input(row(1, 2));
710 test_composite_type_input
711 ---------------------------
715 ALTER TYPE named_pair RENAME TO named_pair_2;
716 SELECT test_composite_type_input(row(1, 2));
717 test_composite_type_input
718 ---------------------------
723 -- Prepared statements
725 CREATE OR REPLACE FUNCTION test_prep_bool_input() RETURNS int
728 plan = plpy.prepare("SELECT CASE WHEN $1 THEN 1 ELSE 0 END AS val", ['boolean'])
729 rv = plpy.execute(plan, ['fa'], 5) # 'fa' is true in Python
732 SELECT test_prep_bool_input(); -- 1
734 ----------------------
738 CREATE OR REPLACE FUNCTION test_prep_bool_output() RETURNS bool
741 plan = plpy.prepare("SELECT $1 = 1 AS val", ['int'])
742 rv = plpy.execute(plan, [0], 5)
746 SELECT test_prep_bool_output(); -- false
748 CONTEXT: PL/Python function "test_prep_bool_output"
749 test_prep_bool_output
750 -----------------------
754 CREATE OR REPLACE FUNCTION test_prep_bytea_input(bb bytea) RETURNS int
757 plan = plpy.prepare("SELECT octet_length($1) AS val", ['bytea'])
758 rv = plpy.execute(plan, [bb], 5)
761 SELECT test_prep_bytea_input(E'a\\000b'); -- 3 (embedded null formerly truncated value)
762 test_prep_bytea_input
763 -----------------------
767 CREATE OR REPLACE FUNCTION test_prep_bytea_output() RETURNS bytea
770 plan = plpy.prepare("SELECT decode('aa00bb', 'hex') AS val")
771 rv = plpy.execute(plan, [], 5)
775 SELECT test_prep_bytea_output();
776 INFO: {'val': b'\xaa\x00\xbb'}
777 CONTEXT: PL/Python function "test_prep_bytea_output"
778 test_prep_bytea_output
779 ------------------------