* array_position_common * Common code for array_position and array_position_start * * These are separate wrappers for the sake of opr_sanity regression test. * They are not strict so we have to test for null inputs explicitly. */
| 1494 | * They are not strict so we have to test for null inputs explicitly. |
| 1495 | */ |
| 1496 | static Datum |
| 1497 | array_position_common(FunctionCallInfo fcinfo) |
| 1498 | { |
| 1499 | ArrayType *array; |
| 1500 | Oid collation = PG_GET_COLLATION(); |
| 1501 | Oid element_type; |
| 1502 | Datum searched_element, |
| 1503 | value; |
| 1504 | bool isnull; |
| 1505 | int position, |
| 1506 | position_min; |
| 1507 | bool found = false; |
| 1508 | TypeCacheEntry *typentry; |
| 1509 | ArrayMetaState *my_extra; |
| 1510 | bool null_search; |
| 1511 | ArrayIterator array_iterator; |
| 1512 | |
| 1513 | if (PG_ARGISNULL(0)) |
| 1514 | PG_RETURN_NULL(); |
| 1515 | |
| 1516 | array = PG_GETARG_ARRAYTYPE_P(0); |
| 1517 | element_type = ARR_ELEMTYPE(array); |
| 1518 | |
| 1519 | /* |
| 1520 | * We refuse to search for elements in multi-dimensional arrays, since we |
| 1521 | * have no good way to report the element's location in the array. |
| 1522 | */ |
| 1523 | if (ARR_NDIM(array) > 1) |
| 1524 | ereport(ERROR, |
| 1525 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 1526 | errmsg("searching for elements in multidimensional arrays is not supported"))); |
| 1527 | |
| 1528 | if (PG_ARGISNULL(1)) |
| 1529 | { |
| 1530 | /* fast return when the array doesn't have nulls */ |
| 1531 | if (!array_contains_nulls(array)) |
| 1532 | PG_RETURN_NULL(); |
| 1533 | searched_element = (Datum) 0; |
| 1534 | null_search = true; |
| 1535 | } |
| 1536 | else |
| 1537 | { |
| 1538 | searched_element = PG_GETARG_DATUM(1); |
| 1539 | null_search = false; |
| 1540 | } |
| 1541 | |
| 1542 | position = (ARR_LBOUND(array))[0] - 1; |
| 1543 | |
| 1544 | /* figure out where to start */ |
| 1545 | if (PG_NARGS() == 3) |
| 1546 | { |
| 1547 | if (PG_ARGISNULL(2)) |
| 1548 | ereport(ERROR, |
| 1549 | (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), |
| 1550 | errmsg("initial position must not be null"))); |
| 1551 | |
| 1552 | position_min = PG_GETARG_INT32(2); |
| 1553 | } |
no test coverage detected