MCPcopy Create free account
hub / github.com/apache/cloudberry / array_position_common

Function array_position_common

src/backend/utils/adt/array_userfuncs.c:1496–1634  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

1494 * They are not strict so we have to test for null inputs explicitly.
1495 */
1496static Datum
1497array_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 }

Callers 2

array_positionFunction · 0.85
array_position_startFunction · 0.85

Calls 13

array_contains_nullsFunction · 0.85
MemoryContextAllocFunction · 0.85
get_typlenbyvalalignFunction · 0.85
lookup_type_cacheFunction · 0.85
format_type_beFunction · 0.85
fmgr_info_cxtFunction · 0.85
array_create_iteratorFunction · 0.85
array_iterateFunction · 0.85
DatumGetBoolFunction · 0.85
FunctionCall2CollFunction · 0.85
array_free_iteratorFunction · 0.85
errcodeFunction · 0.50

Tested by

no test coverage detected