Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kijM0-0004F5-QO for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Nov 2020 19:24:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kijLz-0003xU-K0 for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Nov 2020 19:24:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kijLz-0003xN-Ct for pgsql-hackers@lists.postgresql.org; Fri, 27 Nov 2020 19:24:23 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kijLx-0005Ua-CO for pgsql-hackers@postgresql.org; Fri, 27 Nov 2020 19:24:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 0ARJO93b721456; Fri, 27 Nov 2020 14:24:09 -0500 From: Tom Lane To: Patrick Handja cc: Heikki Linnakangas , pgsql-hackers@postgresql.org Subject: Re: Setof RangeType returns In-reply-to: References: <1b469b07-eede-38d8-3876-8d98ed077ddd@iki.fi> Comments: In-reply-to Patrick Handja message dated "Fri, 27 Nov 2020 13:46:49 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <721454.1606505049.1@sss.pgh.pa.us> Date: Fri, 27 Nov 2020 14:24:09 -0500 Message-ID: <721455.1606505049@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Patrick Handja 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