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"
......@@ -91,208 +91,208 @@ CREATE TRIGGER show_trigger_data_trig_stmt
BEFORE INSERT OR UPDATE OR DELETE OR TRUNCATE ON trigger_test
FOR EACH STATEMENT EXECUTE PROCEDURE trigger_data(23,'skidoo');
insert into trigger_test values(1,'insert');
NOTICE: ("TD[args] => ['23', 'skidoo']",)
NOTICE: TD[args] => ['23', 'skidoo']
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[event] => INSERT',)
NOTICE: TD[event] => INSERT
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[level] => STATEMENT',)
NOTICE: TD[level] => STATEMENT
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[name] => show_trigger_data_trig_stmt',)
NOTICE: TD[name] => show_trigger_data_trig_stmt
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[new] => None',)
NOTICE: TD[new] => None
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[old] => None',)
NOTICE: TD[old] => None
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[relid] => bogus:12345',)
NOTICE: TD[relid] => bogus:12345
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_name] => trigger_test',)
NOTICE: TD[table_name] => trigger_test
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_schema] => public',)
NOTICE: TD[table_schema] => public
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[when] => BEFORE',)
NOTICE: TD[when] => BEFORE
CONTEXT: PL/Python function "trigger_data"
NOTICE: ("TD[args] => ['23', 'skidoo']",)
NOTICE: TD[args] => ['23', 'skidoo']
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[event] => INSERT',)
NOTICE: TD[event] => INSERT
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[level] => ROW',)
NOTICE: TD[level] => ROW
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[name] => show_trigger_data_trig_before',)
NOTICE: TD[name] => show_trigger_data_trig_before
CONTEXT: PL/Python function "trigger_data"
NOTICE: ("TD[new] => {'i': 1, 'v': 'insert'}",)
NOTICE: TD[new] => {'i': 1, 'v': 'insert'}
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[old] => None',)
NOTICE: TD[old] => None
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[relid] => bogus:12345',)
NOTICE: TD[relid] => bogus:12345
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_name] => trigger_test',)
NOTICE: TD[table_name] => trigger_test
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_schema] => public',)
NOTICE: TD[table_schema] => public
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[when] => BEFORE',)
NOTICE: TD[when] => BEFORE
CONTEXT: PL/Python function "trigger_data"
NOTICE: ("TD[args] => ['23', 'skidoo']",)
NOTICE: TD[args] => ['23', 'skidoo']
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[event] => INSERT',)
NOTICE: TD[event] => INSERT
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[level] => ROW',)
NOTICE: TD[level] => ROW
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[name] => show_trigger_data_trig_after',)
NOTICE: TD[name] => show_trigger_data_trig_after
CONTEXT: PL/Python function "trigger_data"
NOTICE: ("TD[new] => {'i': 1, 'v': 'insert'}",)
NOTICE: TD[new] => {'i': 1, 'v': 'insert'}
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[old] => None',)
NOTICE: TD[old] => None
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[relid] => bogus:12345',)
NOTICE: TD[relid] => bogus:12345
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_name] => trigger_test',)
NOTICE: TD[table_name] => trigger_test
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_schema] => public',)
NOTICE: TD[table_schema] => public
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[when] => AFTER',)
NOTICE: TD[when] => AFTER
CONTEXT: PL/Python function "trigger_data"
update trigger_test set v = 'update' where i = 1;
NOTICE: ("TD[args] => ['23', 'skidoo']",)
NOTICE: TD[args] => ['23', 'skidoo']
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[event] => UPDATE',)
NOTICE: TD[event] => UPDATE
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[level] => STATEMENT',)
NOTICE: TD[level] => STATEMENT
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[name] => show_trigger_data_trig_stmt',)
NOTICE: TD[name] => show_trigger_data_trig_stmt
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[new] => None',)
NOTICE: TD[new] => None
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[old] => None',)
NOTICE: TD[old] => None
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[relid] => bogus:12345',)
NOTICE: TD[relid] => bogus:12345
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_name] => trigger_test',)
NOTICE: TD[table_name] => trigger_test
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_schema] => public',)
NOTICE: TD[table_schema] => public
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[when] => BEFORE',)
NOTICE: TD[when] => BEFORE
CONTEXT: PL/Python function "trigger_data"
NOTICE: ("TD[args] => ['23', 'skidoo']",)
NOTICE: TD[args] => ['23', 'skidoo']
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[event] => UPDATE',)
NOTICE: TD[event] => UPDATE
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[level] => ROW',)
NOTICE: TD[level] => ROW
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[name] => show_trigger_data_trig_before',)
NOTICE: TD[name] => show_trigger_data_trig_before
CONTEXT: PL/Python function "trigger_data"
NOTICE: ("TD[new] => {'i': 1, 'v': 'update'}",)
NOTICE: TD[new] => {'i': 1, 'v': 'update'}
CONTEXT: PL/Python function "trigger_data"
NOTICE: ("TD[old] => {'i': 1, 'v': 'insert'}",)
NOTICE: TD[old] => {'i': 1, 'v': 'insert'}
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[relid] => bogus:12345',)
NOTICE: TD[relid] => bogus:12345
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_name] => trigger_test',)
NOTICE: TD[table_name] => trigger_test
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_schema] => public',)
NOTICE: TD[table_schema] => public
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[when] => BEFORE',)
NOTICE: TD[when] => BEFORE
CONTEXT: PL/Python function "trigger_data"
NOTICE: ("TD[args] => ['23', 'skidoo']",)
NOTICE: TD[args] => ['23', 'skidoo']
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[event] => UPDATE',)
NOTICE: TD[event] => UPDATE
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[level] => ROW',)
NOTICE: TD[level] => ROW
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[name] => show_trigger_data_trig_after',)
NOTICE: TD[name] => show_trigger_data_trig_after
CONTEXT: PL/Python function "trigger_data"
NOTICE: ("TD[new] => {'i': 1, 'v': 'update'}",)
NOTICE: TD[new] => {'i': 1, 'v': 'update'}
CONTEXT: PL/Python function "trigger_data"
NOTICE: ("TD[old] => {'i': 1, 'v': 'insert'}",)
NOTICE: TD[old] => {'i': 1, 'v': 'insert'}
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[relid] => bogus:12345',)
NOTICE: TD[relid] => bogus:12345
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_name] => trigger_test',)
NOTICE: TD[table_name] => trigger_test
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_schema] => public',)
NOTICE: TD[table_schema] => public
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[when] => AFTER',)
NOTICE: TD[when] => AFTER
CONTEXT: PL/Python function "trigger_data"
delete from trigger_test;
NOTICE: ("TD[args] => ['23', 'skidoo']",)
NOTICE: TD[args] => ['23', 'skidoo']
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[event] => DELETE',)
NOTICE: TD[event] => DELETE
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[level] => STATEMENT',)
NOTICE: TD[level] => STATEMENT
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[name] => show_trigger_data_trig_stmt',)
NOTICE: TD[name] => show_trigger_data_trig_stmt
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[new] => None',)
NOTICE: TD[new] => None
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[old] => None',)
NOTICE: TD[old] => None
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[relid] => bogus:12345',)
NOTICE: TD[relid] => bogus:12345
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_name] => trigger_test',)
NOTICE: TD[table_name] => trigger_test
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_schema] => public',)
NOTICE: TD[table_schema] => public
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[when] => BEFORE',)
NOTICE: TD[when] => BEFORE
CONTEXT: PL/Python function "trigger_data"
NOTICE: ("TD[args] => ['23', 'skidoo']",)
NOTICE: TD[args] => ['23', 'skidoo']
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[event] => DELETE',)
NOTICE: TD[event] => DELETE
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[level] => ROW',)
NOTICE: TD[level] => ROW
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[name] => show_trigger_data_trig_before',)
NOTICE: TD[name] => show_trigger_data_trig_before
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[new] => None',)
NOTICE: TD[new] => None
CONTEXT: PL/Python function "trigger_data"
NOTICE: ("TD[old] => {'i': 1, 'v': 'update'}",)
NOTICE: TD[old] => {'i': 1, 'v': 'update'}
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[relid] => bogus:12345',)
NOTICE: TD[relid] => bogus:12345
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_name] => trigger_test',)
NOTICE: TD[table_name] => trigger_test
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_schema] => public',)
NOTICE: TD[table_schema] => public
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[when] => BEFORE',)
NOTICE: TD[when] => BEFORE
CONTEXT: PL/Python function "trigger_data"
NOTICE: ("TD[args] => ['23', 'skidoo']",)
NOTICE: TD[args] => ['23', 'skidoo']
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[event] => DELETE',)
NOTICE: TD[event] => DELETE
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[level] => ROW',)
NOTICE: TD[level] => ROW
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[name] => show_trigger_data_trig_after',)
NOTICE: TD[name] => show_trigger_data_trig_after
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[new] => None',)
NOTICE: TD[new] => None
CONTEXT: PL/Python function "trigger_data"
NOTICE: ("TD[old] => {'i': 1, 'v': 'update'}",)
NOTICE: TD[old] => {'i': 1, 'v': 'update'}
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[relid] => bogus:12345',)
NOTICE: TD[relid] => bogus:12345
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_name] => trigger_test',)
NOTICE: TD[table_name] => trigger_test
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_schema] => public',)
NOTICE: TD[table_schema] => public
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[when] => AFTER',)
NOTICE: TD[when] => AFTER
CONTEXT: PL/Python function "trigger_data"
truncate table trigger_test;
NOTICE: ("TD[args] => ['23', 'skidoo']",)
NOTICE: TD[args] => ['23', 'skidoo']
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[event] => TRUNCATE',)
NOTICE: TD[event] => TRUNCATE
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[level] => STATEMENT',)
NOTICE: TD[level] => STATEMENT
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[name] => show_trigger_data_trig_stmt',)
NOTICE: TD[name] => show_trigger_data_trig_stmt
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[new] => None',)
NOTICE: TD[new] => None
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[old] => None',)
NOTICE: TD[old] => None
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[relid] => bogus:12345',)
NOTICE: TD[relid] => bogus:12345
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_name] => trigger_test',)
NOTICE: TD[table_name] => trigger_test
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[table_schema] => public',)
NOTICE: TD[table_schema] => public
CONTEXT: PL/Python function "trigger_data"
NOTICE: ('TD[when] => BEFORE',)
NOTICE: TD[when] => BEFORE
CONTEXT: PL/Python function "trigger_data"
DROP FUNCTION trigger_data() CASCADE;
NOTICE: drop cascades to 3 other objects
......
/**********************************************************************
* 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,6 +3080,15 @@ PLy_output(volatile int level, PyObject *self, PyObject *args)
char *volatile sv;
volatile MemoryContext oldcontext;
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))
{
......
......@@ -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