Re: Weird type selection choice

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Weird type selection choice
Date: 2007-11-06 16:01:13
Message-ID: 21234.1194364873@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)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, then the declared type of the
result is approximate numeric.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gevik Babakhani 2007-11-06 16:20:42 Opinion / advice needed for TODO: function params ref by name
Previous Message Peter Eisentraut 2007-11-06 15:50:08 Re: Weird type selection choice