Re: When is an explicit cast necessary?

From: Alan Millington <admillington(at)yahoo(dot)co(dot)uk>
To: Greg Smith <greg(at)2ndquadrant(dot)com>
Cc: Postgres general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: When is an explicit cast necessary?
Date: 2010-04-09 14:57:21
Message-ID: 998289.88719.qm@web25402.mail.ukl.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thank you for that helpful information. I thought I was going mad!
 
It would never have occurred to me to write a join which relied on an implicit cast between int and string. However, every language that I have ever used will implicitly convert an integer 1 to a smallint (or short) 1 when required to do so. How can such a cast be called "surprising behaviour", or produce "misleading results", to quote the first article?

--- On Fri, 9/4/10, Greg Smith <greg(at)2ndquadrant(dot)com> wrote:

From: Greg Smith <greg(at)2ndquadrant(dot)com>
Subject: Re: [GENERAL] When is an explicit cast necessary?
To: "Alan Millington" <admillington(at)yahoo(dot)co(dot)uk>
Cc: "Postgres general mailing list" <pgsql-general(at)postgresql(dot)org>
Date: Friday, 9 April, 2010, 15:06

Alan Millington wrote:
>
> As far as I remember, when I was using Postgres 8.1.4 that worked, but under Postgres 8.4.1 it results in the errors "Returned type integer does not match expected type smallint" and "Returned type unknown does not match expected type character".
>

There was a major breaking change to how casting is handled in 8.3.  Some good reading about what happened:

http://www.depesz.com/index.php/2008/05/05/error-operator-does-not-exist-integer-text-how-to-fix-it/
http://petereisentraut.blogspot.com/2008/03/readding-implicit-casts-in-postgresql.html

-- Greg Smith  2ndQuadrant US  Baltimore, MD
PostgreSQL Training, Services and Support
greg(at)2ndQuadrant(dot)com   www.2ndQuadrant.us

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greg Smith 2010-04-09 15:11:26 Re: When is an explicit cast necessary?
Previous Message Chris.Ellis 2010-04-09 14:41:14 Re: [Fwd: Re: fulltext search stemming/ spelling problems]