some problem with casting unknown to smallint

Started by Pavel Stehuleover 17 years ago5 messageshackers
Jump to latest
#1Pavel Stehule
pavel.stehule@gmail.com

Hello

I am not sure, it's probably bug.

postgres=# create function t1(smallint) returns smallint as $$select
$1$$ language sql;
CREATE FUNCTION
postgres=# create function t2(bigint) returns bigint as $$select $1$$
language sql;
CREATE FUNCTION
postgres=# select t1(10);
ERROR: function t1(integer) does not exist
LINE 1: select t1(10);
^
HINT: No function matches the given name and argument types. You
might need to add explicit type casts.

but
postgres=# select t2(10);
t2
----
10
(1 row)

Regards
Pavel Stehule

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Pavel Stehule (#1)
Re: some problem with casting unknown to smallint

"Pavel Stehule" <pavel.stehule@gmail.com> writes:

I am not sure, it's probably bug.

postgres=# create function t1(smallint) returns smallint as $$select
$1$$ language sql;
CREATE FUNCTION
postgres=# select t1(10);
ERROR: function t1(integer) does not exist

That's not "unknown to smallint", that's "integer to smallint",
which is not an implicit cast.

unknown to smallint would be t1('10')

regards, tom lane

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: Tom Lane (#2)
Re: some problem with casting unknown to smallint

2008/10/29 Tom Lane <tgl@sss.pgh.pa.us>:

"Pavel Stehule" <pavel.stehule@gmail.com> writes:

I am not sure, it's probably bug.

postgres=# create function t1(smallint) returns smallint as $$select
$1$$ language sql;
CREATE FUNCTION
postgres=# select t1(10);
ERROR: function t1(integer) does not exist

That's not "unknown to smallint", that's "integer to smallint",
which is not an implicit cast.

unknown to smallint would be t1('10')

I understand. So every smallint should be call with casting?

regards
Pavel Stehule

Show quoted text

regards, tom lane

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Pavel Stehule (#3)
Re: some problem with casting unknown to smallint

"Pavel Stehule" <pavel.stehule@gmail.com> writes:

I understand. So every smallint should be call with casting?

A long time ago we tried to make small integer literals be interpreted
as int2 initially, instead of int4, and the attempt failed rather
spectacularly. (It broke most of the regression tests, IIRC, in ways
that suggested that many client applications would have problems too.)
Perhaps PG's type system has matured to the point where it'd work better
now, but I'm not really interested in trying it. I don't see very much
point in declaring functions to take smallint rather than int anyway...

regards, tom lane

#5Pavel Stehule
pavel.stehule@gmail.com
In reply to: Tom Lane (#4)
Re: some problem with casting unknown to smallint

2008/10/29 Tom Lane <tgl@sss.pgh.pa.us>:

"Pavel Stehule" <pavel.stehule@gmail.com> writes:

I understand. So every smallint should be call with casting?

A long time ago we tried to make small integer literals be interpreted
as int2 initially, instead of int4, and the attempt failed rather
spectacularly. (It broke most of the regression tests, IIRC, in ways
that suggested that many client applications would have problems too.)
Perhaps PG's type system has matured to the point where it'd work better
now, but I'm not really interested in trying it. I don't see very much
point in declaring functions to take smallint rather than int anyway...

I found this question on one czech it specialized site. It's mostly
beginner's problem.

regards
Pavel Stehule

Show quoted text

regards, tom lane