From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
Cc: | "robb(at)helical(dot)com" <robb(at)helical(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org> |
Subject: | Re: BUG #18390: exponentiation produces float datatype, but nth-root produces integer |
Date: | 2024-03-13 14:12:10 |
Message-ID: | 2043864.1710339130@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Tuesday, March 12, 2024, PG Bug reporting form <noreply(at)postgresql(dot)org>
> wrote:
>> However, an nth-root calculation from that float result does NOT produce a
>> new float result:
> The issue is you expect dividing two integers to produce a float but that
> isn’t 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.
=# 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
From | Date | Subject | |
---|---|---|---|
Next Message | Noah Misch | 2024-03-13 16:55:23 | Re: FSM Corruption (was: Could not read block at end of the relation) |
Previous Message | Laurenz Albe | 2024-03-13 13:00:29 | Re: BUG #18391: not able to create a new cluster using init db on rocky linux.We are forced to download version 1 3 |