Re: When is an explicit cast necessary? - Mailing list pgsql-general

From Alban Hertroys
Subject Re: When is an explicit cast necessary?
Date
Msg-id 8A9CE1BF-F854-4AA0-9AA6-D232A0034D1E@solfertje.student.utwente.nl
Whole thread Raw
In response to Re: When is an explicit cast necessary?  (Alan Millington <admillington@yahoo.co.uk>)
Responses Re: When is an explicit cast necessary?
List pgsql-general
On 9 Apr 2010, at 16:57, Alan Millington wrote:

> However, every language that I have ever used will implicitly convert an integer 1 to a smallint (or short) 1 when
requiredto do so. How can such a cast be called "surprising behaviour", or produce "misleading results", to quote the
firstarticle? 

No, they probably don't cast integer values down to smallint. What they do is cast the smallint up to integer, as
that'sa safe cast. After all, numbers that fit in an int may not fit in a smallint (try "select 75000::smallint;" for
example)and you'd lose data casting it down, but it's fine the other way around. 

Since your function has smallint as one of its parameter types the database can't cast the smallint up to an int like
itwould normally do in such cases as the function doesn't accept integer values for that parameter. PG can't do much
butthrow an error. 

Alban Hertroys

--
Screwing up is an excellent way to attach something to the ceiling.


!DSPAM:737,4bc0584910411899921361!



pgsql-general by date:

Previous
From: Allan Kamau
Date:
Subject: @> and <@ (contains and is contained by) operations on large arrays
Next
From: Alan Millington
Date:
Subject: Re: When is an explicit cast necessary?