Commit 2e3b16c8 authored by Peter Eisentraut's avatar Peter Eisentraut

Improve PL/Python elog output

When the elog functions (plpy.info etc.) get a single argument, just print
that argument instead of printing the single-member tuple like ('foo',).
parent 2fe1b4dd
......@@ -51,7 +51,7 @@ return "sha hash of " + plain + " is " + digest.hexdigest()'
-- import python modules
--
SELECT import_fail();
NOTICE: ('import socket failed -- No module named foosocket',)
NOTICE: import socket failed -- No module named foosocket
CONTEXT: PL/Python function "import_fail"
import_fail
--------------------
......
......@@ -125,7 +125,7 @@ else:
return None
$$ LANGUAGE plpythonu;
SELECT result_nrows_test();
INFO: (True,)
INFO: True
CONTEXT: PL/Python function "result_nrows_test"
result_nrows_test
-------------------
......
......@@ -32,21 +32,24 @@ plpy.debug('debug')
plpy.log('log')
plpy.info('info')
plpy.info(37)
plpy.info()
plpy.info('info', 37, [1, 2, 3])
plpy.notice('notice')
plpy.warning('warning')
plpy.error('error')
$$ LANGUAGE plpythonu;
SELECT elog_test();
INFO: ('info',)
INFO: info
CONTEXT: PL/Python function "elog_test"
INFO: (37,)
INFO: 37
CONTEXT: PL/Python function "elog_test"
INFO: ()
CONTEXT: PL/Python function "elog_test"
INFO: ('info', 37, [1, 2, 3])
CONTEXT: PL/Python function "elog_test"
NOTICE: ('notice',)
NOTICE: notice
CONTEXT: PL/Python function "elog_test"
WARNING: ('warning',)
WARNING: warning
CONTEXT: PL/Python function "elog_test"
ERROR: ('error',)
ERROR: error
CONTEXT: PL/Python function "elog_test"
/**********************************************************************
* plpython.c - python as a procedural language for PostgreSQL
*
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.131 2009/11/03 09:35:18 petere Exp $
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.132 2009/11/03 11:05:02 petere Exp $
*
*********************************************************************
*/
......@@ -3080,7 +3080,16 @@ PLy_output(volatile int level, PyObject *self, PyObject *args)
char *volatile sv;
volatile MemoryContext oldcontext;
so = PyObject_Str(args);
if (PyTuple_Size(args) == 1)
{
/* Treat single argument specially to avoid undesirable
* ('tuple',) decoration. */
PyObject *o;
PyArg_UnpackTuple(args, "plpy.elog", 1, 1, &o);
so = PyObject_Str(o);
}
else
so = PyObject_Str(args);
if (so == NULL || ((sv = PyString_AsString(so)) == NULL))
{
level = ERROR;
......
......@@ -27,6 +27,7 @@ plpy.debug('debug')
plpy.log('log')
plpy.info('info')
plpy.info(37)
plpy.info()
plpy.info('info', 37, [1, 2, 3])
plpy.notice('notice')
plpy.warning('warning')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment