PL/Python: Add result object str handler

This is intended so that say plpy.debug(rv) prints something useful for
debugging query execution results.

reviewed by Steve Singer
This commit is contained in:
Peter Eisentraut
2013-02-03 00:31:01 -05:00
parent d2d153fdb0
commit 330ed4ac6c
4 changed files with 61 additions and 1 deletions

View File

@ -263,6 +263,24 @@ CONTEXT: PL/Python function "result_empty_test"
(1 row)
CREATE FUNCTION result_str_test(cmd text) RETURNS text
AS $$
plan = plpy.prepare(cmd)
result = plpy.execute(plan)
return str(result)
$$ LANGUAGE plpythonu;
SELECT result_str_test($$SELECT 1 AS foo, '11'::text AS bar UNION SELECT 2, '22'$$);
result_str_test
--------------------------------------------------------------------------------------
<PLyResult status=5 nrows=2 rows=[{'foo': 1, 'bar': '11'}, {'foo': 2, 'bar': '22'}]>
(1 row)
SELECT result_str_test($$CREATE TEMPORARY TABLE foo1 (a int, b text)$$);
result_str_test
--------------------------------------
<PLyResult status=4 nrows=0 rows=[]>
(1 row)
-- cursor objects
CREATE FUNCTION simple_cursor_test() RETURNS int AS $$
res = plpy.cursor("select fname, lname from users")