PG_RETURN_NULL();
array = PG_GETARG_ARRAYTYPE_P(0);
- element_type = ARR_ELEMTYPE(array);
/*
* We refuse to search for elements in multi-dimensional arrays, since we
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("searching for elements in multidimensional arrays is not supported")));
+ /* Searching in an empty array is well-defined, though: it always fails */
+ if (ARR_NDIM(array) < 1)
+ PG_RETURN_NULL();
+
if (PG_ARGISNULL(1))
{
/* fast return when the array doesn't have nulls */
null_search = false;
}
+ element_type = ARR_ELEMTYPE(array);
position = (ARR_LBOUND(array))[0] - 1;
/* figure out where to start */
PG_RETURN_NULL();
array = PG_GETARG_ARRAYTYPE_P(0);
- element_type = ARR_ELEMTYPE(array);
-
- position = (ARR_LBOUND(array))[0] - 1;
/*
* We refuse to search for elements in multi-dimensional arrays, since we
astate = initArrayResult(INT4OID, CurrentMemoryContext, false);
+ /* Searching in an empty array is well-defined, though: it always fails */
+ if (ARR_NDIM(array) < 1)
+ PG_RETURN_DATUM(makeArrayResult(astate, CurrentMemoryContext));
+
if (PG_ARGISNULL(1))
{
/* fast return when the array doesn't have nulls */
null_search = false;
}
+ element_type = ARR_ELEMTYPE(array);
+ position = (ARR_LBOUND(array))[0] - 1;
+
/*
* We arrange to look up type info for array_create_iterator only once per
* series of calls, assuming the element type doesn't change underneath