Re: Interesting abilities of substring - Mailing list pgsql-general

From Tom Lane
Subject Re: Interesting abilities of substring
Date
Msg-id 18492.1186684231@sss.pgh.pa.us
Whole thread Raw
In response to Re: Interesting abilities of substring  (Kenneth Downs <ken@secdat.com>)
List pgsql-general
Kenneth Downs <ken@secdat.com> writes:
> Tom Lane wrote:
>> Implicit casts to text are evil, and are mostly going to be gone in 8.3.
>> So try not to rely on this behavior ...

> Based on general principle, or on specific bad things like unexpected or
> ill-defined results?

Both.  Check the archives, and you'll see reports every few months from
people who got bit by unexpected misinterpretations of queries.  The
typical case is someone who tries to compare values of two different
datatypes, and the most plausible interpretation the parser can find
is to implicitly cast them both to text and use text comparison :-(.
Another thing we've seen happen is that someone thinks he's invoking
substring(text,int), but his second argument isn't int but float or
numeric, and instead of an error he gets substring(text,text) which
does Something Completely Different from what he expects.

The problem with an implicit cast is basically that it'll kick in when
you didn't want or expect it.  So in CVS HEAD most casts to text are not
implicit anymore, and we've put in some much more limited flexibility:
the || operator will take any data type and do an implicit coercion to
text, so long as at least one of the inputs is of a string type.  (We
had some problems not breaking the array interpretation of ||, but
surmounted those.)  It might be possible to do something similar for
substring, but I'm not sure how to put any flexibility there without
re-introducing the problem alluded to above.

            regards, tom lane

pgsql-general by date:

Previous
From: Erik Jones
Date:
Subject: Re: Reordering columns, will this ever be simple?
Next
From: "Joshua D. Drake"
Date:
Subject: Re: Reordering columns, will this ever be simple?