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

From Martijn van Oosterhout
Subject Re: When is an explicit cast necessary?
Date
Msg-id 20100410195939.GB6944@svana.org
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?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Sat, Apr 10, 2010 at 05:15:18PM +0000, Alan Millington wrote:
> In C, if I declare a short variable shortvar, I can write an
> assignment shortvar = 1. The literal value 1 is an int, but the
> compiler will implicitly convert it to a short. Similarly, if I write
> a function func() which takes a short argument, then provided I use
> function prototypes, I can write a call func(1). Again the compiler
> will implicitly convert the int 1 to a short.

The problem is basically that postgres sees the 1 not as a literal but
as an integer, which can't be downcast to a smallint. If however you
wrote the literal as '1' (with quotes) postgres would happily downcast
it for you without any problem.

The question is: does the column really need to be smallint.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patriotism is when love of your own people comes first; nationalism,
> when hate for people other than your own comes first.
>                                       - Charles de Gaulle

Attachment

pgsql-general by date:

Previous
From: Alan Millington
Date:
Subject: Re: When is an explicit cast necessary?
Next
From: Peter Eisentraut
Date:
Subject: Re: psql's \d display of unique index vs. constraint