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 1jw6yX-0003XM-8d for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Jul 2020 16:43:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jw6yW-0005mB-5B for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Jul 2020 16:43:12 +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 1jw6yV-0005hv-UQ for pgsql-hackers@lists.postgresql.org; Thu, 16 Jul 2020 16:43:11 +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 1jw6yT-0000bH-IY for pgsql-hackers@lists.postgresql.org; Thu, 16 Jul 2020 16:43:10 +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 06GGh7jR3362333; Thu, 16 Jul 2020 12:43:07 -0400 From: Tom Lane To: Dean Rasheed cc: PostgreSQL Hackers Subject: Re: Infinities in type numeric In-reply-to: References: <606717.1591924582@sss.pgh.pa.us> <1368929.1592328296@sss.pgh.pa.us> Comments: In-reply-to Dean Rasheed message dated "Thu, 16 Jul 2020 00:39:33 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3362331.1594917787.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 16 Jul 2020 12:43:07 -0400 Message-ID: <3362332.1594917787@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Dean Rasheed writes: > I had a look at this, and I think it's mostly in good shape. It looks > like everything from the first message in this thread has been > resolved, except I don't know about the jsonpath stuff, because I > haven't been following that. Thanks for the careful review! Yeah, Alexander fixed the jsonpath stuff at df646509f, so I think all my original concerns are cleared, other than the question of whether to invent isfinite() and isnan() SQL functions. That seems like follow-on work in any case. > 1). I don't think that the way in_range() handles infinities is quite > right. For example: > SELECT in_range('inf'::numeric, 10::numeric, 'inf'::numeric, false, fals= e); > in_range > ---------- > f > (1 row) > But I think that should return "val >=3D base + offset", which is "Inf > >=3D Inf", which should be true. Hmm. I modeled the logic on the float8 in_range code, which does the same thing: # SELECT in_range('inf'::float8, 10::float8, 'inf'::float8, false, false); in_range = ---------- f (1 row) It does seem like this is wrong per the specification of in_range, though, so do we have a bug to fix in the float in_range support? If so I'd be inclined to go correct that first and then adapt the numeric patch to match. > Similarly, I think this should return true: > SELECT in_range('-inf'::numeric, 10::numeric, 'inf'::numeric, true, true= ); Same comment. > I think this could use some test coverage. Evidently :-( > 2). I think numeric_pg_lsn() needs updating -- this should probably be a= n error: Oh, that was not there when I produced my patch. Will cover it in the next version. I agree with your other comments and will update the patch. > Finally, not really in the scope of this patch, but something I > noticed anyway while looking at edge cases -- float and numeric handle > NaN/0 differently: > SELECT 'nan'::float8 / 0::float8; > ERROR: division by zero > SELECT 'nan'::numeric / 0::numeric; > ?column? > ---------- > NaN Hmm. It seems like we generally ought to try to follow IEEE 754 for the semantics of operations on NaN, but I don't have a copy of that spec so I'm not sure which result it specifies for this. I agree that being inconsistent between the two types is not what we want. regards, tom lane