From: | stark <stark(at)enterprisedb(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Casts |
Date: | 2006-08-09 11:21:40 |
Message-ID: | 87hd0m6tob.fsf@enterprisedb.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> stark <stark(at)enterprisedb(dot)com> writes:
>> It seems odd to me that implicit casts are checked for when you call a
>> function but not when you're implicitly calling a function via a cast. As a
>> result there are a *lot* of redundant casts in our catalog, essentially n!
>> casts for a domain with n types in it. So for example there are 138 casts
>> between the various numeric data types including every possible pairing of
>> char, int2, int4, int8, float4, float8, and numeric.
>
> This is intentional. If you explicitly cast type foo to type bar there
> should not be any question about what function will be invoked. The
> cost is a few more rows in pg_cast ... so what?
And hundreds of lines of copy-pasted code with potential bugs.
> As for "the parser ought to be able to find two-step cast pathways",
> no thanks. The increase in search time and the decrease in
> predictability are both undesirable.
>
>> There has been some fear expressed in the past that too many implicit casts
>> create surprising side effects.
>
> Not "some fear" ... we have seen people badly burned, time and time
> again, by the ill-considered implicit casts that are already in there.
> IMHO we need fewer implicit casts, not more.
I agree we need fewer implicit casts. But I think you take that too far to
dogmatically imply that every implicit cast is suspect.
I think the ideal combination is having every type have precisely one implicit
cast "up" the type "tree" and assignment casts down the "tree". I don't see us
every needing anything more complex than a flat "tree" of a single base type
for each domain and everyone directly a child of that one type. So every
numeric data type would have an implicit cast to numeric, every text type
would have an implicit cast to text, etc.
The implicit casts from numeric to other types seem suspect to me. And there
are tons of cases where we have implicit casts in both directions such as bit
to varbit and varbit to bit. That makes no sense to me. That would be where
the surprising effects come from.
As long as every type has precisely one implicit cast up I think it would
become safe to rely on it for many of the operations and not have to define
redundant operations for every data type.
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | Simon Riggs | 2006-08-09 11:48:08 | Re: [HACKERS] Restartable Recovery |
Previous Message | Florian G. Pflug | 2006-08-09 10:57:39 | Re: An Idea for planner hints |