Patrick Handja <patrick.bung...@gmail.com> writes: > This is what I am doing:
> static int > get_range_lower(FunctionCallInfo fcinfo, RangeType *r1) > { > /* Return NULL if there's no finite lower bound */ > if (empty || lower.infinite) > PG_RETURN_NULL(); You can't really use PG_RETURN_NULL here, mainly because there is no good value for it to return from get_range_lower(). > return (lower.val); Here and elsewhere, you're cavalierly casting between Datum and int. While you can get away with that as long as the SQL type you're working with is int4, it's bad style; mainly because it's confusing, but also because you'll have a hard time adapting the code if you ever want to work with some other type. Use DatumGetInt32 or Int32GetDatum as appropriate. > TypeCacheEntry *typcache; > PG_RETURN_RANGE_P(range_serialize(typcache, &lower, &upper, false)); This sure appears to be passing an uninitialized typcache pointer to range_serialize(). If your compiler isn't whining about that, you don't have adequately paranoid warning options enabled. That's an excellent way to waste a lot of time, as you just have. C is an unforgiving language, so you need all the help you can get. BTW, use of PG_RETURN_RANGE_P here isn't very appropriate either, since the function is not declared as returning Datum. regards, tom lane