Error code missing for "wrong length of inner sequence" error

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Error code missing for "wrong length of inner sequence" error
Date: 2020-10-01 10:54:43
Message-ID: 634ced13-1cc5-6a88-c880-3b1410238450@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

In PLySequence_ToArray_recurse(), there's this check:

> if (PySequence_Length(list) != dims[dim])
> ereport(ERROR,
> (errmsg("wrong length of inner sequence: has length %d, but %d was expected",
> (int) PySequence_Length(list), dims[dim]),
> (errdetail("To construct a multidimensional array, the inner sequences must all have the same length."))));

It's missing an error code, making it implicitly ERRCODE_INTERNAL_ERROR,
which is surely not right. That's simple to fix, but what error code
should we use?

I'm inclined to use ERRCODE_ARRAY_SUBSCRIPT_ERROR, because that's used
in the similar error message with SQL ARRAY expression, like "ARRAY[[1],
[2, 3]]". Most checks when converting between SQL and Python types use
the PLy_elog() function, which uses the genericc
ERRCODE_EXTERNAL_ROUTINE_EXCEPTION error code, but I think
ERRCODE_ARRAY_SUBSCRIPT_ERROR is better.

You get this error e.g. if you try to return a python lists of lists
from a PL/python function as a multi-dimensional array, but the sublists
have different lengths:

create function return_array() returns int[] as $$
return [[1], [1,2]]
$$ language plpythonu;

postgres=# select return_array();
ERROR: wrong length of inner sequence: has length 2, but 1 was expected
DETAIL: To construct a multidimensional array, the inner sequences must
all have the same length.
CONTEXT: while creating return value
PL/Python function "return_array"

Thoughts? If not, I'm going to add
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR) to that.

- Heikki

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2020-10-01 11:14:35 Re: Logical replication CPU-bound with TRUNCATE/DROP/CREATE many tables
Previous Message Amit Kapila 2020-10-01 09:37:50 Re: Logical replication CPU-bound with TRUNCATE/DROP/CREATE many tables