Re: Weird type selection choice - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Weird type selection choice
Date
Msg-id 21234.1194364873@sss.pgh.pa.us
Whole thread Raw
In response to Weird type selection choice  (Peter Eisentraut <peter_e@gmx.net>)
Responses Re: Weird type selection choice  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-hackers
Peter Eisentraut <peter_e@gmx.net> writes:
> It apparently casts the 1 to double precision to pick the variant
> trunc(dp)=>dp instead of trunc(numeric)=>numeric.  I was under the impression
> that we didn't want to cast integers to float types implicitly because this
> loses information.  Clearly, the numeric variant should be preferred anyway.

There's nothing "clear" about that at all.  float8 is the preferred type
in the numeric category, so preferring trunc(dp) over trunc(numeric) is
exactly what I'd expect to happen.  This is not something that can be
readily changed, because if we made numeric the preferred type we'd be
violating the SQL spec.  The result of, for example, float8 + numeric
has to be float8:
        2) If the declared type of either operand of a dyadic arithmetic           operator is approximate numeric,
thenthe declared type of the           result is approximate numeric.
 
        regards, tom lane


pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Weird type selection choice
Next
From: "Gevik Babakhani"
Date:
Subject: Opinion / advice needed for TODO: function params ref by name