Re: When is an explicit cast necessary?

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: When is an explicit cast necessary?
Дата
Msg-id 20100410195939.GB6944@svana.org
обсуждение исходный текст
Ответ на Re: When is an explicit cast necessary?  (Alan Millington <admillington@yahoo.co.uk>)
Ответы Re: When is an explicit cast necessary?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Alan Millington
Дата:
Сообщение: Re: When is an explicit cast necessary?
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: psql's \d display of unique index vs. constraint