Re: Implicit coercions, choosing types for constants, etc - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: Implicit coercions, choosing types for constants, etc
Date
Msg-id Pine.LNX.4.44.0211111937480.12428-100000@localhost.localdomain
Whole thread Raw
In response to Implicit coercions, choosing types for constants, etc (yet again)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Tom Lane writes:

> One way to fix this is to make cross-category coercions to text not be
> implicit casts.  (I've opined before that that's a bad idea, but not
> gotten a lot of support for changing it.  Now that we have a distinction
> between implicit and assignment casts, perhaps we could consider making
> coercions to text be assignment casts, as a compromise?)

I thought we had agreed to make those explicit.  In fact, I vaguely recall
you not liking that notion ...

> I suppose we could fix this particular case by eliminating
> to_hex(integer), or adding to_hex(smallint), but that seems a very
> unsatisfying answer.  I am wondering about adding some notion of
> "conversion distance" associated with casts, and preferring choices
> that require a smaller conversion distance; perhaps this could replace
> the concept of "preferred type", too.  But again I don't have a specific
> proposal to make.  Any thoughts?

A couple of months ago I played around with the notion of adding a numeric
preference ("distance", as you call it) to the casts, but in the end this
solved only a small number of cases and created a big mess at the same
time.  When you have to pick arbitrary distances, any algorithm will give
you arbitrary answers, after all.

I think we can construct a type precedence list using the existing catalog
information.  Considering the example of choosing between int2->int4 and
int2->int8, the system could notice that there is an implicit cast
int4->int8 (and no implicit cast the other way), so int4 is "less" than
int8.  (If there were an implicit cast int8->int4, then the system would
have to consider int4 and int8 to be equivalent and picking one at random
would be reasonable.)

-- 
Peter Eisentraut   peter_e@gmx.net



pgsql-hackers by date:

Previous
From: "Robert E. Bruccoleri"
Date:
Subject: Re: Problem with 7.3 on Irix with dates before 1970
Next
From: "Curtis Faith"
Date:
Subject: 500 tpsQL + WAL log implementation