From: | Patrick Handja <patrick(dot)bungama(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Setof RangeType returns |
Date: | 2020-12-01 21:42:56 |
Message-ID: | CAOKRWVA9n-8U-QS7M_oyQ3ZeeFDcjpF=5iexnjYvsHoRvc-FdA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Thanks for the feedback Tom!
> TypeCacheEntry *typcache;
> PG_RETURN_RANGE_P(range_serialize(typcache, &lower, &upper, false));
The use of typcache really confuses me. range_get_typcache() is used in
order to initialize typcache
> typcache =range_get_typcache(fcinfo, RangeTypeGetOid(r1));
In my case, I do not have a range as an argument, I am receiving 2 int,
which I am using to create a range. How can I initialize typcache in this
case?
That's the part where I am really stuck.
Datum
make_range_griis(PG_FUNCTION_ARGS){
RangeBound lower;
RangeBound upper;
int32 start = PG_GETARG_INT32(0);
int32 finish = PG_GETARG_INT32(1);
lower.val = (Datum) (start);
lower.infinite = false;
lower.lower = true;
upper.val = (Datum) (finish);
upper.infinite = false;
upper.lower = false;
if (!lower.infinite && !lower.inclusive){
lower.val = DirectFunctionCall2(int4pl, lower.val, Int32GetDatum(1));
lower.inclusive = true;
}
if (!upper.infinite && upper.inclusive){
upper.val = DirectFunctionCall2(int4pl, upper.val, Int32GetDatum(1));
upper.inclusive = false;
}
TypeCacheEntry *typcache;
//> typcache = ??????;
PG_RETURN_RANGE_P(range_serialize(typcache, &lower, &upper, false));
}
regards,
*Andjasubu Bungama, Patrick *
Le ven. 27 nov. 2020 à 14:24, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> a écrit :
> Patrick Handja <patrick(dot)bungama(at)gmail(dot)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
>
From | Date | Subject | |
---|---|---|---|
Next Message | Zidenberg, Tsahi | 2020-12-01 21:43:53 | Re: Improving spin-lock implementation on ARM. |
Previous Message | Paul Martinez | 2020-12-01 21:39:19 | Proposal: Adding isbgworker column to pg_stat_activity |