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 1jjjwY-0000M6-71 for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jun 2020 13:42:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jjjwX-0005kt-3U for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jun 2020 13:42:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jjjwW-0005j2-SD for pgsql-hackers@lists.postgresql.org; Fri, 12 Jun 2020 13:42:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jjjwU-0008Rz-G9 for pgsql-hackers@lists.postgresql.org; Fri, 12 Jun 2020 13:42:00 +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 05CDfurP663833; Fri, 12 Jun 2020 09:41:56 -0400 From: Tom Lane To: Andrew Gierth cc: pgsql-hackers@lists.postgresql.org Subject: Re: Infinities in type numeric In-reply-to: <87lfks5uwl.fsf@news-spur.riddles.org.uk> References: <606717.1591924582@sss.pgh.pa.us> <87lfks5uwl.fsf@news-spur.riddles.org.uk> Comments: In-reply-to Andrew Gierth message dated "Fri, 12 Jun 2020 13:47:19 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <663831.1591969316.1@sss.pgh.pa.us> Date: Fri, 12 Jun 2020 09:41:56 -0400 Message-ID: <663832.1591969316@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andrew Gierth writes: > "Tom" == Tom Lane writes: > Tom> +#define NUMERIC_ABBREV_PINF NumericAbbrevGetDatum(PG_INT64_MIN) > Tom> +#define NUMERIC_ABBREV_PINF NumericAbbrevGetDatum(PG_INT32_MIN) > I'd have been more inclined to go with -PG_INT64_MAX / -PG_INT32_MAX for > the NUMERIC_ABBREV_PINF value. It seems more likely to be beneficial to > bucket +Inf and NaN separately (and put +Inf in with the "too large to > abbreviate" values) than to bucket them together so as to distinguish > between +Inf and "too large" values. But this is an edge case in any > event, so it probably wouldn't make a great deal of difference unless > you're sorting on data with a large proportion of both +Inf and NaN > values. I had been worried about things possibly sorting in the wrong order if I did that. However, now that I look more closely I see that * We convert the absolute value of the numeric to a 31-bit or 63-bit positive * value, and then negate it if the original number was positive. so that a finite value should never map to INT[64]_MIN, making it safe to do as you suggest. I agree that distinguishing +Inf from NaN is probably more useful than distinguishing it from the very largest class of finite values, so will do it as you suggest. Thanks! regards, tom lane