| 34 | #define NEXTVAL(x) ( (ltree*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) ) |
| 35 | |
| 36 | static bool |
| 37 | array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found) |
| 38 | { |
| 39 | int num = ArrayGetNItems(ARR_NDIM(la), ARR_DIMS(la)); |
| 40 | ltree *item = (ltree *) ARR_DATA_PTR(la); |
| 41 | |
| 42 | if (ARR_NDIM(la) > 1) |
| 43 | ereport(ERROR, |
| 44 | (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), |
| 45 | errmsg("array must be one-dimensional"))); |
| 46 | if (array_contains_nulls(la)) |
| 47 | ereport(ERROR, |
| 48 | (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), |
| 49 | errmsg("array must not contain nulls"))); |
| 50 | |
| 51 | if (found) |
| 52 | *found = NULL; |
| 53 | while (num > 0) |
| 54 | { |
| 55 | if (DatumGetBool(DirectFunctionCall2(callback, |
| 56 | PointerGetDatum(item), PointerGetDatum(param)))) |
| 57 | { |
| 58 | |
| 59 | if (found) |
| 60 | *found = item; |
| 61 | return true; |
| 62 | } |
| 63 | num--; |
| 64 | item = NEXTVAL(item); |
| 65 | } |
| 66 | |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | Datum |
| 71 | _ltree_isparent(PG_FUNCTION_ARGS) |
no test coverage detected