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

From: bricklen <bricklen(at)gmail(dot)com>
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:20:35
Message-ID: CAGrpgQ9tJsOHcF4B4UU-k+s9D3WFL4POWiaEVK3NeQ6So_6G1Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Jul 29, 2013 at 8:11 AM, John DeSoi <desoi(at)pgedit(dot)com> wrote:

> 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.
>
>
> temp=# create or replace function itest (param smallint) returns integer
> as $$ select $1 + 5; $$ language sql;
> CREATE FUNCTION
> temp=# select itest(5);
> ERROR: function itest(integer) does not exist
> LINE 1: select itest(5);
> ^
> HINT: No function matches the given name and argument types. You might
> need to add explicit type casts.
> temp=# select itest('5');
> itest
> -------
> 10
> (1 row)
>
>

FWIW, It works if you don't rely on the implicit cast, and explicitly cast
it to smallint:

select itest(5::smallint);
itest
-------
10

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2013-07-29 15:31:32 Re: how to get UPDATEXML function in postgresql as it works in oracle
Previous Message Ian Lawrence Barwick 2013-07-29 15:12:31 Re: Viewing another role's search path?