Re: 5 is not a smallint but '5' is

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: 5 is not a smallint but '5' is
Дата
Msg-id 26623.1375112044@sss.pgh.pa.us
обсуждение исходный текст
Ответ на 5 is not a smallint but '5' is  (John DeSoi <desoi@pgedit.com>)
Список pgsql-general
John DeSoi <desoi@pgedit.com> writes:
> I was surprised to discover this today. I can work around it, but it seems counterintuitive. If 5 can't be parsed as
asmallint, I would feel better if '5' was not one either. 

Yeah, 5 is an int not a smallint, but '5' is not a smallint: it's a
literal of unknown type, for which we try to deduce a type from context.

> temp=# select itest(5);
> ERROR:  function itest(integer) does not exist
> temp=# select itest('5');
>  itest
> -------
>     10
> (1 row)

In this example, since you only have one function named itest(),
the parser is able to deduce that the literal must be intended
to be of type smallint.

By and large, since there's an implicit cast from smallint to int and
not vice versa, it's usually best to declare functions as taking int
even if you expect they'll mainly be called with smallint parameters.

            regards, tom lane


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

Предыдущее
От: Alban Hertroys
Дата:
Сообщение: Re: how to get UPDATEXML function in postgresql as it works in oracle
Следующее
От: Raghavendra
Дата:
Сообщение: Re: how to get UPDATEXML function in postgresql as it works in oracle