From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | John DeSoi <desoi(at)pgedit(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org general" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: 5 is not a smallint but '5' is |
Date: | 2013-07-29 15:34:04 |
Message-ID: | 26623.1375112044@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
John DeSoi <desoi(at)pgedit(dot)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 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
From | Date | Subject | |
---|---|---|---|
Next Message | Raghavendra | 2013-07-29 15:40:38 | Re: how to get UPDATEXML function in postgresql as it works in oracle |
Previous Message | Alban Hertroys | 2013-07-29 15:31:32 | Re: how to get UPDATEXML function in postgresql as it works in oracle |