mirror of
https://github.com/postgres/postgres.git
synced 2026-01-13 12:22:55 +03:00
Augment test coverage in PL/Python, especially for error conditions.
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
--
|
||||
-- Test returning tuples
|
||||
--
|
||||
CREATE TABLE table_record (
|
||||
first text,
|
||||
second int4
|
||||
) ;
|
||||
CREATE TYPE type_record AS (
|
||||
first text,
|
||||
second int4
|
||||
) ;
|
||||
CREATE FUNCTION test_table_record_as(typ text, first text, second integer, retnull boolean) RETURNS table_record AS $$
|
||||
if retnull:
|
||||
return None
|
||||
@@ -298,3 +306,26 @@ SELECT * FROM test_inout_params('test_in');
|
||||
test_in_inout
|
||||
(1 row)
|
||||
|
||||
-- errors cases
|
||||
CREATE FUNCTION test_type_record_error1() RETURNS type_record AS $$
|
||||
return { 'first': 'first' }
|
||||
$$ LANGUAGE plpythonu;
|
||||
SELECT * FROM test_type_record_error1();
|
||||
ERROR: key "second" not found in mapping
|
||||
HINT: To return null in a column, add the value None to the mapping with the key named after the column.
|
||||
CONTEXT: PL/Python function "test_type_record_error1"
|
||||
CREATE FUNCTION test_type_record_error2() RETURNS type_record AS $$
|
||||
return [ 'first' ]
|
||||
$$ LANGUAGE plpythonu;
|
||||
SELECT * FROM test_type_record_error2();
|
||||
ERROR: length of returned sequence did not match number of columns in row
|
||||
CONTEXT: PL/Python function "test_type_record_error2"
|
||||
CREATE FUNCTION test_type_record_error3() RETURNS type_record AS $$
|
||||
class type_record: pass
|
||||
type_record.first = 'first'
|
||||
return type_record
|
||||
$$ LANGUAGE plpythonu;
|
||||
SELECT * FROM test_type_record_error3();
|
||||
ERROR: attribute "second" does not exist in Python object
|
||||
HINT: To return null in a column, let the returned object have an attribute named after column with value None.
|
||||
CONTEXT: PL/Python function "test_type_record_error3"
|
||||
|
||||
Reference in New Issue
Block a user