Re: some problem with casting unknown to smallint

Lists: pgsql-hackers
From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "postgres hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: some problem with casting unknown to smallint
Date: 2008-10-29 08:07:01
Message-ID: 162867790810290107q73e2c40cre30aa492d5af52e0@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "postgres hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: some problem with casting unknown to smallint
Date: 2008-10-29 12:21:02
Message-ID: 11058.1225282862@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)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


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "postgres hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: some problem with casting unknown to smallint
Date: 2008-10-29 12:31:46
Message-ID: 162867790810290531j632a5336of4846cbe2331e7bb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/10/29 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)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

> regards, tom lane
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "postgres hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: some problem with casting unknown to smallint
Date: 2008-10-29 12:44:07
Message-ID: 11408.1225284247@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)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


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "postgres hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: some problem with casting unknown to smallint
Date: 2008-10-29 12:52:41
Message-ID: 162867790810290552l7c18613n8ae67c0413a18a8c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/10/29 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)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

>
> regards, tom lane
>