#include "postgres.h" #include "access/gist.h" #include "access/itup.h" #include "access/rtree.h" #include "utils/elog.h" #include "utils/palloc.h" #include "utils/array.h" #include "utils/builtins.h" #include "storage/bufpage.h" PG_FUNCTION_INFO_V1(level); Datum level(PG_FUNCTION_ARGS); Datum level(PG_FUNCTION_ARGS) { int nitems,ndim,*dim; char *p=0; ArrayType *intarray = (ArrayType *) DatumGetPointer(PG_GETARG_DATUM(0)); if (intarray == 0 ) return (int4) 0; intarray = DatumGetArrayTypeP(PointerGetDatum(intarray)); if (intarray == 0 ) return (int4) 0; p = ARR_DATA_PTR(intarray); if (p == 0) return (int4) 0; ndim = ARR_NDIM(intarray); dim = ARR_DIMS(intarray); nitems = ArrayGetNItems(ndim, dim); return (int4) nitems; }