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 1p6lAS-0005OZ-9h for pgsql-general@arkaria.postgresql.org; Sun, 18 Dec 2022 04:20:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p6lAR-0007zh-0C for pgsql-general@arkaria.postgresql.org; Sun, 18 Dec 2022 04:20:51 +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 1p6lAQ-0007zY-MU for pgsql-general@lists.postgresql.org; Sun, 18 Dec 2022 04:20:50 +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 1p6lAO-0005np-FY for pgsql-general@lists.postgresql.org; Sun, 18 Dec 2022 04:20:50 +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 2BI4KjtS157203; Sat, 17 Dec 2022 23:20:45 -0500 From: Tom Lane To: "Martin L. Buchanan" cc: pgsql-general@lists.postgresql.org Subject: Re: integer square root function proposed In-reply-to: References: Comments: In-reply-to "Martin L. Buchanan" message dated "Sat, 17 Dec 2022 19:39:44 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <157201.1671337245.1@sss.pgh.pa.us> Date: Sat, 17 Dec 2022 23:20:45 -0500 Message-ID: <157202.1671337245@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Martin L. Buchanan" writes: > Reading the documentation I found no built-in function for integer square > root, requiring a sequence of: > floor(sqrt(foo))::integer > to go from an integer to the integer square root as an integer. I'm a little down on this idea, mainly because I doubt there is any principled argument as to whether the rounding ought to be down, up, or to nearest. Specific applications probably want a specific one of those, but how likely is it that a built-in choice would satisfy many users? I'm not buying the performance angle too much either. Even granting that your platform has an integer square root instruction that's faster than its floating-point one, and that we can get at that from C, the difference would likely be swamped by the overhead of the SQL function call. > (And with infinities and NaNs processed as described in > 8.1 Numeric Types). Our integers do not have infinities, nor NaNs. Anyway, I don't mean to slam the door on this idea completely, but I think you need to make a much better-supported argument for it. regards, tom lane