提交 1681ae16 编写于 作者: H Heikki Linnakangas 提交者: Heikki Linnakangas

Tidy up error reporting when converting PL/Python arrays.

Use PLy_elog() only when a call to a Python C API function failed, and
ereport() for other errors. Add an error code to the "wrong length of
inner sequence" ereport().

Reviewed-by: Daniel Gustafsson
Discussion: https://www.postgresql.org/message-id/B8B72889-D6D7-48FF-B782-D670A6CA4D37%40yesql.se
上级 95b20b8d
...@@ -1180,18 +1180,25 @@ PLySequence_ToArray(PLyObToDatum *arg, PyObject *plrv, ...@@ -1180,18 +1180,25 @@ PLySequence_ToArray(PLyObToDatum *arg, PyObject *plrv,
break; break;
if (ndim == MAXDIM) if (ndim == MAXDIM)
PLy_elog(ERROR, "number of array dimensions exceeds the maximum allowed (%d)", MAXDIM); ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("number of array dimensions exceeds the maximum allowed (%d)",
MAXDIM)));
dims[ndim] = PySequence_Length(pyptr); dims[ndim] = PySequence_Length(pyptr);
if (dims[ndim] < 0) if (dims[ndim] < 0)
PLy_elog(ERROR, "could not determine sequence length for function return value"); PLy_elog(ERROR, "could not determine sequence length for function return value");
if (dims[ndim] > MaxAllocSize) if (dims[ndim] > MaxAllocSize)
PLy_elog(ERROR, "array size exceeds the maximum allowed"); ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("array size exceeds the maximum allowed")));
len *= dims[ndim]; len *= dims[ndim];
if (len > MaxAllocSize) if (len > MaxAllocSize)
PLy_elog(ERROR, "array size exceeds the maximum allowed"); ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("array size exceeds the maximum allowed")));
if (dims[ndim] == 0) if (dims[ndim] == 0)
{ {
...@@ -1217,7 +1224,9 @@ PLySequence_ToArray(PLyObToDatum *arg, PyObject *plrv, ...@@ -1217,7 +1224,9 @@ PLySequence_ToArray(PLyObToDatum *arg, PyObject *plrv,
if (ndim == 0) if (ndim == 0)
{ {
if (!PySequence_Check(plrv)) if (!PySequence_Check(plrv))
PLy_elog(ERROR, "return value of function with array return type is not a Python sequence"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("return value of function with array return type is not a Python sequence")));
ndim = 1; ndim = 1;
len = dims[0] = PySequence_Length(plrv); len = dims[0] = PySequence_Length(plrv);
...@@ -1261,10 +1270,9 @@ PLySequence_ToArray_recurse(PLyObToDatum *elm, PyObject *list, ...@@ -1261,10 +1270,9 @@ PLySequence_ToArray_recurse(PLyObToDatum *elm, PyObject *list,
{ {
int i; int i;
/* GPDB_12_MERGE_FIXME: This has no errcode in upstream. Submit that to upstream? */
if (PySequence_Length(list) != dims[dim]) if (PySequence_Length(list) != dims[dim])
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("wrong length of inner sequence: has length %d, but %d was expected", errmsg("wrong length of inner sequence: has length %d, but %d was expected",
(int) PySequence_Length(list), dims[dim]), (int) PySequence_Length(list), dims[dim]),
(errdetail("To construct a multidimensional array, the inner sequences must all have the same length.")))); (errdetail("To construct a multidimensional array, the inner sequences must all have the same length."))));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册