Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



John DeSoi <desoi@xxxxxxxxxx> writes:
> I was surprised to discover this today. I can work around it, but it seems counterintuitive. If 5 can't be parsed as a smallint, 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


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux