From: Tom Lane <tgl@sss.pgh.pa.us>
To: Patrick Handja <patrick.bungama@gmail.com>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: pgsql-hackers@postgresql.org
Subject: Re: Setof RangeType returns
Date: Fri, 27 Nov 2020 14:24:09 -0500
Message-ID: <721455.1606505049@sss.pgh.pa.us> (raw)
In-Reply-To: <CAOKRWVBU5dxL5MawXhdSBVcSNC1qnaVTUsMCUU3+LpA5dznaYg@mail.gmail.com>
References: <CAOKRWVCrbjGzW4DGNod5TVFTZYLPZnc5jWhFLPLi1jTHw=NHtA@mail.gmail.com>
<1b469b07-eede-38d8-3876-8d98ed077ddd@iki.fi>
<CAOKRWVBU5dxL5MawXhdSBVcSNC1qnaVTUsMCUU3+LpA5dznaYg@mail.gmail.com>
Patrick Handja <patrick.bungama@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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, patrick.bungama@gmail.com, hlinnaka@iki.fi
Subject: Re: Setof RangeType returns
In-Reply-To: <721455.1606505049@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox