Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rkPNV-00CY6m-J2 for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Mar 2024 14:14:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rkPNU-004tJl-4g for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Mar 2024 14:14:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rkPLF-004nwU-Rn for pgsql-bugs@lists.postgresql.org; Wed, 13 Mar 2024 14:12:26 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rkPLC-004JAg-TM for pgsql-bugs@lists.postgresql.org; Wed, 13 Mar 2024 14:12:25 +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 42DECAP22043865; Wed, 13 Mar 2024 10:12:10 -0400 From: Tom Lane To: "David G. Johnston" cc: "robb@helical.com" , "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #18390: exponentiation produces float datatype, but nth-root produces integer In-reply-to: References: <18390-03499fe4f5a0ac71@postgresql.org> Comments: In-reply-to "David G. Johnston" message dated "Wed, 13 Mar 2024 05:07:35 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2043863.1710339130.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 13 Mar 2024 10:12:10 -0400 Message-ID: <2043864.1710339130@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Tuesday, March 12, 2024, PG Bug reporting form > wrote: >> However, an nth-root calculation from that float result does NOT produc= e a >> new float result: > The issue is you expect dividing two integers to produce a float but tha= t > isn=E2=80=99t how that works. Dividing two integers produces an integer= . In this > case zero, or .1 rounded down/truncated. Possibly adding to the OP's confusion: not one of these examples contains any float arithmetic whatsoever. They're of type numeric. =3D# select pg_typeof(2.5937424601000000^(1.0/10)); pg_typeof = ----------- numeric (1 row) See https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX= -CONSTANTS-NUMERIC which says A numeric constant that contains neither a decimal point nor an exponent is initially presumed to be type integer if its value fits in type integer (32 bits); otherwise it is presumed to be type bigint if its value fits in type bigint (64 bits); otherwise it is taken to be type numeric. Constants that contain decimal points and/or exponents are always initially presumed to be type numeric. A cast to float would occur only if the value is fed to an operator that doesn't come in an exactly matching datatype. regards, tom lane