DETAIL: ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
-- should fail
DO $$ plpy.info('wrong sqlstate', sqlstate='54444A') $$ LANGUAGE plpythonu;
-ERROR: invalid SQLSTATE code
-CONTEXT: PL/Python anonymous code block
+ERROR: ValueError: invalid SQLSTATE code
+CONTEXT: Traceback (most recent call last):
+ PL/Python anonymous code block, line 1, in <module>
+ plpy.info('wrong sqlstate', sqlstate='54444A')
+PL/Python anonymous code block
DO $$ plpy.info('unsupported argument', blabla='fooboo') $$ LANGUAGE plpythonu;
-ERROR: 'blabla' is an invalid keyword argument for this function
-CONTEXT: PL/Python anonymous code block
+ERROR: TypeError: 'blabla' is an invalid keyword argument for this function
+CONTEXT: Traceback (most recent call last):
+ PL/Python anonymous code block, line 1, in <module>
+ plpy.info('unsupported argument', blabla='fooboo')
+PL/Python anonymous code block
DO $$ plpy.info('first message', message='second message') $$ LANGUAGE plpythonu;
-ERROR: the message is already specified
-CONTEXT: PL/Python anonymous code block
+ERROR: TypeError: Argument 'message' given by name and position
+CONTEXT: Traceback (most recent call last):
+ PL/Python anonymous code block, line 1, in <module>
+ plpy.info('first message', message='second message')
+PL/Python anonymous code block
DO $$ plpy.info('first message', 'second message', message='third message') $$ LANGUAGE plpythonu;
-ERROR: the message is already specified
-CONTEXT: PL/Python anonymous code block
+ERROR: TypeError: Argument 'message' given by name and position
+CONTEXT: Traceback (most recent call last):
+ PL/Python anonymous code block, line 1, in <module>
+ plpy.info('first message', 'second message', message='third message')
+PL/Python anonymous code block
-- raise exception in python, handle exception in plgsql
CREATE OR REPLACE FUNCTION raise_exception(_message text, _detail text DEFAULT NULL, _hint text DEFAULT NULL,
_sqlstate text DEFAULT NULL,
{
/* the message should not be overwriten */
if (PyTuple_Size(args) != 0)
- PLy_elog(ERROR, "the message is already specified");
+ {
+ PLy_exception_set(PyExc_TypeError, "Argument 'message' given by name and position");
+ return NULL;
+ }
if (message)
pfree(message);
else if (strcmp(keyword, "constraint_name") == 0)
constraint_name = object_to_string(value);
else
- PLy_elog(ERROR, "'%s' is an invalid keyword argument for this function",
- keyword);
+ {
+ PLy_exception_set(PyExc_TypeError,
+ "'%s' is an invalid keyword argument for this function",
+ keyword);
+ return NULL;
+ }
}
}
if (sqlstatestr != NULL)
{
if (strlen(sqlstatestr) != 5)
- PLy_elog(ERROR, "invalid SQLSTATE code");
+ {
+ PLy_exception_set(PyExc_ValueError, "invalid SQLSTATE code");
+ return NULL;
+ }
if (strspn(sqlstatestr, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != 5)
- PLy_elog(ERROR, "invalid SQLSTATE code");
+ {
+ PLy_exception_set(PyExc_ValueError, "invalid SQLSTATE code");
+ return NULL;
+ }
sqlstate = MAKE_SQLSTATE(sqlstatestr[0],
sqlstatestr[1],