I'm writing a c function to make a range type on a float range. I find PostgreSQL allows using numrange(low, high) to create a nunrange, but I can't find the corresponding part in the C code. The only method I find(i hope it works) is
TypeCacheEntry *cache=lookup_type_cache(3907,TYPECACHE_RANGE_INFO);
RangeBound lower;
lower.val = Float8GetDatum(b.zmin);
lower.infinite = false;
lower.inclusive = false;
lower.lower = true;
RangeBound upper;
upper.val = Float8GetDatum(b.zmax);
upper.infinite = false;
upper.inclusive = false;
upper.lower = true;
return PointerGetDatum(range_serialize(cache, &lower,&upper,false));
However the solution seems ugly... Could anyone give me some instruction about how to return a numrange in a more beautiful way?
I use DirectFunctionCall like this following the instruction of @Laurenz Albe
Datum s1= DirectFunctionCall1(float8_numeric,Float8GetDatum(b.zmin));
Datum s2= DirectFunctionCall1(float8_numeric,Float8GetDatum(b.zmax));
return DirectFunctionCall2(range_constructor2,s1,s2);
And sadly got a SIGSIEV in range_get_typcache