mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-18 04:17:00 +08:00
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:
@ -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")
|
||||
|
||||
Reference in New Issue
Block a user