On 09/08/10 17:56, Tom Lane wrote:
<vsha...@alliedtesting.com> writes:
I have the problem:
the code sending empty binary array works on 8.3 and 8.4
but stopped working on postgres 9.0 beta2/3/4, it fails with '22003','integer
out of range error'.
I think you are right --- this rejects dim[i] == 0, but it should not.
Yeah, this is also reproducible with COPY:
postgres=# CREATE TABLE arrtest (a int4[]);
CREATE TABLE
postgres=# COPY ( SELECT array_fill(7, ARRAY[0], ARRAY[1]) ) TO '/tmp/a'
BINARY;
COPY 1
postgres=# COPY arrtest FROM '/tmp/a' BINARY;ERROR: integer out of range
CONTEXT: COPY arrtest, line 1, column a
The behavior of empty arrays with dimensions is weird in general. For
example:
postgres=# SELECT array_dims(array_fill(7, ARRAY[0, 1]));
array_dims
------------
[1:0][1:1]
(1 row)
postgres=# SELECT array_fill(7, ARRAY[0, 1]);
array_fill
------------
{}
(1 row)
postgres=# SELECT array_dims('{}'::int4[]);
array_dims
------------
(1 row)
The text representation of such an array is simply '{}', but that loses
information about the dimensions.
I agree that array_recv() should rather accept that than throw an error,
patch attached, but this is pretty weird stuff...
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
*** a/src/backend/utils/adt/arrayfuncs.c
--- b/src/backend/utils/adt/arrayfuncs.c
***************
*** 1213,1229 **** array_recv(PG_FUNCTION_ARGS)
for (i = 0; i < ndim; i++)
{
- int ub;
-
dim[i] = pq_getmsgint(buf, 4);
lBound[i] = pq_getmsgint(buf, 4);
! ub = lBound[i] + dim[i] - 1;
! /* overflow? */
! if (lBound[i] > ub)
! ereport(ERROR,
! (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
! errmsg("integer out of range")));
}
/* This checks for overflow of array dimensions */
--- 1213,1230 ----
for (i = 0; i < ndim; i++)
{
dim[i] = pq_getmsgint(buf, 4);
lBound[i] = pq_getmsgint(buf, 4);
! /* check overflow of upper bound */
! if (dim[i] != 0)
! {
! int ub = lBound[i] + dim[i] - 1;
! if (lBound[i] > ub)
! ereport(ERROR,
! (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
! errmsg("integer out of range")));
! }
}
/* This checks for overflow of array dimensions */
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs