Re: Function with defval returns error

Lists: pgsql-hackers
From: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Function with defval returns error
Date: 2008-12-15 09:04:43
Message-ID: 460abcb10812150104lc779517ofbfcbb4890fca9f7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi All,

Following test returns error on 8.4 cvs head. it looks like an issue

Testcase: (8.4 CVS head)
====================
CREATE OR REPLACE FUNCTION f007( a INTEGER,
b INTEGER DEFAULT 10 ) RETURNS INTEGER
AS $$
select 10;
$$ language sql;

CREATE OR REPLACE FUNCTION f007( a INTEGER DEFAULT 10,
b INTEGER DEFAULT 10,
c INTEGER DEFAULT 10) RETURNS INTEGER
AS $$
select 10;
$$ language sql;

CREATE OR REPLACE FUNCTION f007( a TIMESTAMP DEFAULT to_date('01-JUN-06
14:03:50', 'DD-MON-YY HH24:MI:SS') ) RETURNS TIMESTAMP
AS $$
select current_date::timestamp;
$$ language sql;

postgres=# SELECT f007( to_date('01-JUN-06 14:03:50', 'DD-MON-YY
HH24:MI:SS') );
ERROR: functions with parameter defaults f007(integer, integer, integer)
and f007(integer, integer) are ambiguous

I think this should not return error as the input args here is timestamp...
inputs?

Thanks,
Rushabh Lathia
www.EnterpriseDB.com


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-15 09:13:22
Message-ID: 49461FB2.5050700@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Rushabh Lathia wrote:
> Testcase: (8.4 CVS head)
> ====================
> CREATE OR REPLACE FUNCTION f007( a INTEGER,
> b INTEGER DEFAULT 10 ) RETURNS INTEGER
> AS $$
> select 10;
> $$ language sql;
>
> CREATE OR REPLACE FUNCTION f007( a INTEGER DEFAULT 10,
> b INTEGER DEFAULT 10,
> c INTEGER DEFAULT 10) RETURNS INTEGER
> AS $$
> select 10;
> $$ language sql;
>
> CREATE OR REPLACE FUNCTION f007( a TIMESTAMP DEFAULT
> to_date('01-JUN-06 14:03:50', 'DD-MON-YY HH24:MI:SS') ) RETURNS TIMESTAMP
> AS $$
> select current_date::timestamp;
> $$ language sql;
>
> postgres=# SELECT f007( to_date('01-JUN-06 14:03:50', 'DD-MON-YY
> HH24:MI:SS') );
> ERROR: functions with parameter defaults f007(integer, integer,
> integer) and f007(integer, integer) are ambiguous
>
>
> I think this should not return error as the input args here is
> timestamp... inputs?

In theory yes, but it's currently not that smart. When it considers a
function based on available default values, it does not consider
argument types. So if there is another function with the same number of
arguments, it bails out.

Feel free to propose improvements.


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-15 09:15:09
Message-ID: 162867790812150115w1efd3960n7387127c6295118a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

2008/12/15 Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>:
> Hi All,
>
> Following test returns error on 8.4 cvs head. it looks like an issue
>
> Testcase: (8.4 CVS head)
> ====================
> CREATE OR REPLACE FUNCTION f007( a INTEGER,
> b INTEGER DEFAULT 10 ) RETURNS INTEGER
> AS $$
> select 10;
> $$ language sql;
>
> CREATE OR REPLACE FUNCTION f007( a INTEGER DEFAULT 10,
> b INTEGER DEFAULT 10,
> c INTEGER DEFAULT 10) RETURNS INTEGER
> AS $$
> select 10;
> $$ language sql;
>
> CREATE OR REPLACE FUNCTION f007( a TIMESTAMP DEFAULT to_date('01-JUN-06
> 14:03:50', 'DD-MON-YY HH24:MI:SS') ) RETURNS TIMESTAMP
> AS $$
> select current_date::timestamp;
> $$ language sql;
>
> postgres=# SELECT f007( to_date('01-JUN-06 14:03:50', 'DD-MON-YY
> HH24:MI:SS') );
> ERROR: functions with parameter defaults f007(integer, integer, integer)
> and f007(integer, integer) are ambiguous
>
>
> I think this should not return error as the input args here is timestamp...
> inputs?
>

you are right - this is known problem - because postgresql identify
ambigonous calling and choise the best function in two places - simply
we identify ambigonous call to early (algoritm is more fast then
smart) - so ugly efect is identifivation of stored ambiguous functions
when you call other function with same name.

Pavel

> Thanks,
> Rushabh Lathia
> www.EnterpriseDB.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-15 13:43:00
Message-ID: 26230.1229348580@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> Rushabh Lathia wrote:
>> I think this should not return error as the input args here is
>> timestamp... inputs?

> In theory yes, but it's currently not that smart.

This is truly horrid. Was that patch *really* ready to commit?
I noticed some comments added to polymorphism.sql that certainly
look like there's still a lot of half-bakedness in it.

regards, tom lane


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-15 20:37:50
Message-ID: 200812152237.51872.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Monday 15 December 2008 15:43:00 Tom Lane wrote:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > Rushabh Lathia wrote:
> >> I think this should not return error as the input args here is
> >> timestamp... inputs?
> >
> > In theory yes, but it's currently not that smart.
>
> This is truly horrid. Was that patch *really* ready to commit?
> I noticed some comments added to polymorphism.sql that certainly
> look like there's still a lot of half-bakedness in it.

There is that one case where a call that could be allowed is overly-cautiously
rejected. That only happens if you have a mix of overloading and default
parameters. It's not really half-baked in the sense that it is not
digestible; it's just not the greatest cake yet. It's
improvement-compatible.


From: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>
To: "Peter Eisentraut" <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-16 06:32:24
Message-ID: 460abcb10812152232lefa0e18t78a8236c051eb2ec@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Another issue found on CVS head ....

CREATE USER test WITH PASSWORD 'test';
CREATE SCHEMA AUTHORIZATION test;

CREATE OR REPLACE FUNCTION f_test(x in numeric) RETURNS numeric as $$
BEGIN
RETURN x;
END;
$$ language plpgsql;

select f_test(10);

\c postgres test;

select f_test(10);

CREATE OR REPLACE FUNCTION f_test(x in numeric, y in varchar default 'Local
Function with parameters') RETURNs numeric as $$
BEGIN
RETURN x+1;
END;
$$ language plpgsql;

postgres=> select f_test(10);
ERROR: cache lookup failed for type 2139062142

On Tue, Dec 16, 2008 at 2:07 AM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:

> On Monday 15 December 2008 15:43:00 Tom Lane wrote:
> > Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > > Rushabh Lathia wrote:
> > >> I think this should not return error as the input args here is
> > >> timestamp... inputs?
> > >
> > > In theory yes, but it's currently not that smart.
> >
> > This is truly horrid. Was that patch *really* ready to commit?
> > I noticed some comments added to polymorphism.sql that certainly
> > look like there's still a lot of half-bakedness in it.
>
> There is that one case where a call that could be allowed is
> overly-cautiously
> rejected. That only happens if you have a mix of overloading and default
> parameters. It's not really half-baked in the sense that it is not
> digestible; it's just not the greatest cake yet. It's
> improvement-compatible.
>

--
Rushabh Lathia


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-16 06:56:07
Message-ID: 162867790812152256h3c2f8ce2u5fa227526f90e2d2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

I'll write patch that block creating all ambiguous overloading.

Regards
Pavel Stehule

2008/12/16 Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>:
>
> Another issue found on CVS head ....
>
> CREATE USER test WITH PASSWORD 'test';
> CREATE SCHEMA AUTHORIZATION test;
>
> CREATE OR REPLACE FUNCTION f_test(x in numeric) RETURNS numeric as $$
> BEGIN
> RETURN x;
> END;
> $$ language plpgsql;
>
> select f_test(10);
>
> \c postgres test;
>
> select f_test(10);
>
> CREATE OR REPLACE FUNCTION f_test(x in numeric, y in varchar default 'Local
> Function with parameters') RETURNs numeric as $$
> BEGIN
> RETURN x+1;
> END;
> $$ language plpgsql;
>
> postgres=> select f_test(10);
> ERROR: cache lookup failed for type 2139062142
>
>
>
>
> On Tue, Dec 16, 2008 at 2:07 AM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
>>
>> On Monday 15 December 2008 15:43:00 Tom Lane wrote:
>> > Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
>> > > Rushabh Lathia wrote:
>> > >> I think this should not return error as the input args here is
>> > >> timestamp... inputs?
>> > >
>> > > In theory yes, but it's currently not that smart.
>> >
>> > This is truly horrid. Was that patch *really* ready to commit?
>> > I noticed some comments added to polymorphism.sql that certainly
>> > look like there's still a lot of half-bakedness in it.
>>
>> There is that one case where a call that could be allowed is
>> overly-cautiously
>> rejected. That only happens if you have a mix of overloading and default
>> parameters. It's not really half-baked in the sense that it is not
>> digestible; it's just not the greatest cake yet. It's
>> improvement-compatible.
>
>
>
> --
> Rushabh Lathia
>


From: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-16 07:04:52
Message-ID: 460abcb10812152304y11dc1817n9a7b2b14bdc1a527@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

When we find the (pathpos < prevResult->pathpos) into
FuncnameGetCandidates(), we just replacing the prevResult with the
newResult.

While replacing the previous with new we do not replace the args. I think in
case of default we need to take care for the args as well.

Thanks,
Rushabh

On Tue, Dec 16, 2008 at 12:26 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>wrote:

> Hello
>
> I'll write patch that block creating all ambiguous overloading.
>
> Regards
> Pavel Stehule
>
> 2008/12/16 Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>:
> >
> > Another issue found on CVS head ....
> >
> > CREATE USER test WITH PASSWORD 'test';
> > CREATE SCHEMA AUTHORIZATION test;
> >
> > CREATE OR REPLACE FUNCTION f_test(x in numeric) RETURNS numeric as $$
> > BEGIN
> > RETURN x;
> > END;
> > $$ language plpgsql;
> >
> > select f_test(10);
> >
> > \c postgres test;
> >
> > select f_test(10);
> >
> > CREATE OR REPLACE FUNCTION f_test(x in numeric, y in varchar default
> 'Local
> > Function with parameters') RETURNs numeric as $$
> > BEGIN
> > RETURN x+1;
> > END;
> > $$ language plpgsql;
> >
> > postgres=> select f_test(10);
> > ERROR: cache lookup failed for type 2139062142
> >
> >
> >
> >
> > On Tue, Dec 16, 2008 at 2:07 AM, Peter Eisentraut <peter_e(at)gmx(dot)net>
> wrote:
> >>
> >> On Monday 15 December 2008 15:43:00 Tom Lane wrote:
> >> > Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> >> > > Rushabh Lathia wrote:
> >> > >> I think this should not return error as the input args here is
> >> > >> timestamp... inputs?
> >> > >
> >> > > In theory yes, but it's currently not that smart.
> >> >
> >> > This is truly horrid. Was that patch *really* ready to commit?
> >> > I noticed some comments added to polymorphism.sql that certainly
> >> > look like there's still a lot of half-bakedness in it.
> >>
> >> There is that one case where a call that could be allowed is
> >> overly-cautiously
> >> rejected. That only happens if you have a mix of overloading and
> default
> >> parameters. It's not really half-baked in the sense that it is not
> >> digestible; it's just not the greatest cake yet. It's
> >> improvement-compatible.
> >
> >
> >
> > --
> > Rushabh Lathia
> >
>

--
Rushabh Lathia


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-16 12:05:43
Message-ID: 162867790812160405h32c0d0bdi6bbc9bbd508e0279@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/12/16 Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>:
>
> When we find the (pathpos < prevResult->pathpos) into
> FuncnameGetCandidates(), we just replacing the prevResult with the
> newResult.
>
> While replacing the previous with new we do not replace the args. I think in
> case of default we need to take care for the args as well.
>

personally I prefer raise exception, when I find similar function, we
don't need emulate Oracle behave.

Regards
Pavel Stehule

> Thanks,
> Rushabh
>
> On Tue, Dec 16, 2008 at 12:26 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
>>
>> Hello
>>
>> I'll write patch that block creating all ambiguous overloading.
>>
>> Regards
>> Pavel Stehule
>>
>> 2008/12/16 Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>:
>> >
>> > Another issue found on CVS head ....
>> >
>> > CREATE USER test WITH PASSWORD 'test';
>> > CREATE SCHEMA AUTHORIZATION test;
>> >
>> > CREATE OR REPLACE FUNCTION f_test(x in numeric) RETURNS numeric as $$
>> > BEGIN
>> > RETURN x;
>> > END;
>> > $$ language plpgsql;
>> >
>> > select f_test(10);
>> >
>> > \c postgres test;
>> >
>> > select f_test(10);
>> >
>> > CREATE OR REPLACE FUNCTION f_test(x in numeric, y in varchar default
>> > 'Local
>> > Function with parameters') RETURNs numeric as $$
>> > BEGIN
>> > RETURN x+1;
>> > END;
>> > $$ language plpgsql;
>> >
>> > postgres=> select f_test(10);
>> > ERROR: cache lookup failed for type 2139062142
>> >
>> >
>> >
>> >
>> > On Tue, Dec 16, 2008 at 2:07 AM, Peter Eisentraut <peter_e(at)gmx(dot)net>
>> > wrote:
>> >>
>> >> On Monday 15 December 2008 15:43:00 Tom Lane wrote:
>> >> > Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
>> >> > > Rushabh Lathia wrote:
>> >> > >> I think this should not return error as the input args here is
>> >> > >> timestamp... inputs?
>> >> > >
>> >> > > In theory yes, but it's currently not that smart.
>> >> >
>> >> > This is truly horrid. Was that patch *really* ready to commit?
>> >> > I noticed some comments added to polymorphism.sql that certainly
>> >> > look like there's still a lot of half-bakedness in it.
>> >>
>> >> There is that one case where a call that could be allowed is
>> >> overly-cautiously
>> >> rejected. That only happens if you have a mix of overloading and
>> >> default
>> >> parameters. It's not really half-baked in the sense that it is not
>> >> digestible; it's just not the greatest cake yet. It's
>> >> improvement-compatible.
>> >
>> >
>> >
>> > --
>> > Rushabh Lathia
>> >
>
>
>
> --
> Rushabh Lathia
>


From: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-16 12:16:06
Message-ID: 460abcb10812160416i4d96a102s79a26b7f08870d8a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 16, 2008 at 5:35 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>wrote:

> 2008/12/16 Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>:
> >
> > When we find the (pathpos < prevResult->pathpos) into
> > FuncnameGetCandidates(), we just replacing the prevResult with the
> > newResult.
> >
> > While replacing the previous with new we do not replace the args. I think
> in
> > case of default we need to take care for the args as well.
> >
>
> personally I prefer raise exception, when I find similar function, we
> don't need emulate Oracle behave.

Raise exception when find similar function, do you mean similar function
with different pathpos ? Or similar function with defval ?

>
> Regards
> Pavel Stehule
>
> > Thanks,
> > Rushabh
> >
> > On Tue, Dec 16, 2008 at 12:26 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com
> >
> > wrote:
> >>
> >> Hello
> >>
> >> I'll write patch that block creating all ambiguous overloading.
> >>
> >> Regards
> >> Pavel Stehule
> >>
> >> 2008/12/16 Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>:
> >> >
> >> > Another issue found on CVS head ....
> >> >
> >> > CREATE USER test WITH PASSWORD 'test';
> >> > CREATE SCHEMA AUTHORIZATION test;
> >> >
> >> > CREATE OR REPLACE FUNCTION f_test(x in numeric) RETURNS numeric as $$
> >> > BEGIN
> >> > RETURN x;
> >> > END;
> >> > $$ language plpgsql;
> >> >
> >> > select f_test(10);
> >> >
> >> > \c postgres test;
> >> >
> >> > select f_test(10);
> >> >
> >> > CREATE OR REPLACE FUNCTION f_test(x in numeric, y in varchar default
> >> > 'Local
> >> > Function with parameters') RETURNs numeric as $$
> >> > BEGIN
> >> > RETURN x+1;
> >> > END;
> >> > $$ language plpgsql;
> >> >
> >> > postgres=> select f_test(10);
> >> > ERROR: cache lookup failed for type 2139062142
> >> >
> >> >
> >> >
> >> >
> >> > On Tue, Dec 16, 2008 at 2:07 AM, Peter Eisentraut <peter_e(at)gmx(dot)net>
> >> > wrote:
> >> >>
> >> >> On Monday 15 December 2008 15:43:00 Tom Lane wrote:
> >> >> > Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> >> >> > > Rushabh Lathia wrote:
> >> >> > >> I think this should not return error as the input args here is
> >> >> > >> timestamp... inputs?
> >> >> > >
> >> >> > > In theory yes, but it's currently not that smart.
> >> >> >
> >> >> > This is truly horrid. Was that patch *really* ready to commit?
> >> >> > I noticed some comments added to polymorphism.sql that certainly
> >> >> > look like there's still a lot of half-bakedness in it.
> >> >>
> >> >> There is that one case where a call that could be allowed is
> >> >> overly-cautiously
> >> >> rejected. That only happens if you have a mix of overloading and
> >> >> default
> >> >> parameters. It's not really half-baked in the sense that it is not
> >> >> digestible; it's just not the greatest cake yet. It's
> >> >> improvement-compatible.
> >> >
> >> >
> >> >
> >> > --
> >> > Rushabh Lathia
> >> >
> >
> >
> >
> > --
> > Rushabh Lathia
> >
>

--
Rushabh Lathia


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-16 16:37:21
Message-ID: 162867790812160837k307b097ydbdd040e18ab9d5f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/12/16 Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>:
>
>
> On Tue, Dec 16, 2008 at 5:35 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
>>
>> 2008/12/16 Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>:
>> >
>> > When we find the (pathpos < prevResult->pathpos) into
>> > FuncnameGetCandidates(), we just replacing the prevResult with the
>> > newResult.
>> >
>> > While replacing the previous with new we do not replace the args. I
>> > think in
>> > case of default we need to take care for the args as well.
>> >
>>
>> personally I prefer raise exception, when I find similar function, we
>> don't need emulate Oracle behave.
>
> Raise exception when find similar function, do you mean similar function
> with different pathpos ? Or similar function with defval ?

I mean similar with defval

Pavel

>
>>
>>
>> Regards
>> Pavel Stehule
>>
>> > Thanks,
>> > Rushabh
>> >
>> > On Tue, Dec 16, 2008 at 12:26 PM, Pavel Stehule
>> > <pavel(dot)stehule(at)gmail(dot)com>
>> > wrote:
>> >>
>> >> Hello
>> >>
>> >> I'll write patch that block creating all ambiguous overloading.
>> >>
>> >> Regards
>> >> Pavel Stehule
>> >>
>> >> 2008/12/16 Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>:
>> >> >
>> >> > Another issue found on CVS head ....
>> >> >
>> >> > CREATE USER test WITH PASSWORD 'test';
>> >> > CREATE SCHEMA AUTHORIZATION test;
>> >> >
>> >> > CREATE OR REPLACE FUNCTION f_test(x in numeric) RETURNS numeric as $$
>> >> > BEGIN
>> >> > RETURN x;
>> >> > END;
>> >> > $$ language plpgsql;
>> >> >
>> >> > select f_test(10);
>> >> >
>> >> > \c postgres test;
>> >> >
>> >> > select f_test(10);
>> >> >
>> >> > CREATE OR REPLACE FUNCTION f_test(x in numeric, y in varchar default
>> >> > 'Local
>> >> > Function with parameters') RETURNs numeric as $$
>> >> > BEGIN
>> >> > RETURN x+1;
>> >> > END;
>> >> > $$ language plpgsql;
>> >> >
>> >> > postgres=> select f_test(10);
>> >> > ERROR: cache lookup failed for type 2139062142
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > On Tue, Dec 16, 2008 at 2:07 AM, Peter Eisentraut <peter_e(at)gmx(dot)net>
>> >> > wrote:
>> >> >>
>> >> >> On Monday 15 December 2008 15:43:00 Tom Lane wrote:
>> >> >> > Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
>> >> >> > > Rushabh Lathia wrote:
>> >> >> > >> I think this should not return error as the input args here is
>> >> >> > >> timestamp... inputs?
>> >> >> > >
>> >> >> > > In theory yes, but it's currently not that smart.
>> >> >> >
>> >> >> > This is truly horrid. Was that patch *really* ready to commit?
>> >> >> > I noticed some comments added to polymorphism.sql that certainly
>> >> >> > look like there's still a lot of half-bakedness in it.
>> >> >>
>> >> >> There is that one case where a call that could be allowed is
>> >> >> overly-cautiously
>> >> >> rejected. That only happens if you have a mix of overloading and
>> >> >> default
>> >> >> parameters. It's not really half-baked in the sense that it is not
>> >> >> digestible; it's just not the greatest cake yet. It's
>> >> >> improvement-compatible.
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Rushabh Lathia
>> >> >
>> >
>> >
>> >
>> > --
>> > Rushabh Lathia
>> >
>
>
>
> --
> Rushabh Lathia
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-17 03:05:51
Message-ID: 20057.1229483151@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'll write patch that block creating all ambiguous overloading.

Don't bother --- it's a useless solution because you can't guarantee
that concurrent insertions into pg_proc won't create an ambiguous
situation. You have to define the resolution rules to cope, or else
generate an ambiguous-function error on the fly when the currently
seen contents of pg_proc create an ambiguous situation.

In which connection, there's yet another thing I don't like about
the current patch behavior. Given

create function foo (f1 int, f2 int = 42)
create function foo (f1 int, f2 numeric = 42.0)

select foo(10)

I accept that there's nothing much we can do except throw an "ambiguous
function" error. However, the patch also throws error for

create function foo (f1 int, f2 int = 42)
create function foo (f1 int, f2 int = 42, f2 int = 43)

select foo(10)

It seems to me that we could usefully consider that the function with
fewer defaulted arguments takes precedence. In particular, the limiting
case of that is that a function with no defaulted arguments takes
precedence over those with some. This case *must* work:

create function foo (f1 int)
create function foo (f1 int, f2 int = 42)

select foo(10)

and it seems like just an arbitrary exception if you don't have a rule
about preferring fewer defaults over more.

regards, tom lane


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-18 10:04:46
Message-ID: 494A203E.4050502@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> This case *must* work:
>
> create function foo (f1 int)
> create function foo (f1 int, f2 int = 42)
>
> select foo(10)
>
> and it seems like just an arbitrary exception if you don't have a rule
> about preferring fewer defaults over more.

I tried out C++, and it rejects this case:

#include <iostream>
using namespace std;

int foo(int f1) { return 1; }
int foo(int f1, int f2 = 42) { return 2; }
int foo(int f1, int f2 = 42, int f3 = 43) { return 3; }

int main() {
cout << foo(10) << endl;
}

test.cpp: In function 'int main()':
test.cpp:9: error: call of overloaded 'foo(int)' is ambiguous
test.cpp:4: note: candidates are: int foo(int)
test.cpp:5: note: int foo(int, int)
test.cpp:6: note: int foo(int, int, int)

Interestingly, it complains about the calls, not the declarations, which
is what I might have argued against.

So, I'd rather reject the foo(10) call. The least-defaults rule doesn't
strike me as very appealing. If you are porting Oracle functions with
40 arguments, it's very confusing and error-prone to say that the
35-defaults variant will be called over the 37-default variant, more so
if you extend this to name-based parameter lists where parameters and
defaults can be in any order. The whole thing is probably a mistake and
should be rejected.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-18 14:36:18
Message-ID: 25595.1229610978@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> Tom Lane wrote:
>> This case *must* work:
>>
>> create function foo (f1 int)
>> create function foo (f1 int, f2 int = 42)
>>
>> select foo(10)

> I tried out C++, and it rejects this case:
> ...
> So, I'd rather reject the foo(10) call. The least-defaults rule doesn't
> strike me as very appealing.

OK, I think we're in agreement on this. I'll make it happen.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-18 18:22:17
Message-ID: 10142.1229624537@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com> writes:
> CREATE OR REPLACE FUNCTION f007( a INTEGER,
> b INTEGER DEFAULT 10 ) RETURNS INTEGER
> AS $$
> select 10;
> $$ language sql;

> CREATE OR REPLACE FUNCTION f007( a INTEGER DEFAULT 10,
> b INTEGER DEFAULT 10,
> c INTEGER DEFAULT 10) RETURNS INTEGER
> AS $$
> select 10;
> $$ language sql;

> CREATE OR REPLACE FUNCTION f007( a TIMESTAMP DEFAULT to_date('01-JUN-06
> 14:03:50', 'DD-MON-YY HH24:MI:SS') ) RETURNS TIMESTAMP
> AS $$
> select current_date::timestamp;
> $$ language sql;

> postgres=# SELECT f007( to_date('01-JUN-06 14:03:50', 'DD-MON-YY
> HH24:MI:SS') );
> ERROR: functions with parameter defaults f007(integer, integer, integer)
> and f007(integer, integer) are ambiguous

> I think this should not return error as the input args here is timestamp...

This is fixed in my recent commit --- the ambiguous-function error won't
occur unless the ambiguous functions represent the best match to the
actual arguments.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-18 18:24:15
Message-ID: 10187.1229624655@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com> writes:
> Another issue found on CVS head ....
> ...
> postgres=> select f_test(10);
> ERROR: cache lookup failed for type 2139062142

I had some difficulty reproducing this locally. Would you check it's
fixed by latest commit?

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: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-18 20:16:52
Message-ID: 162867790812181216s48f68576vb3e25af08df52103@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>
> This is fixed in my recent commit --- the ambiguous-function error won't
> occur unless the ambiguous functions represent the best match to the
> actual arguments.
>
> regards, tom lane
>

I did some fast test, and now, it is well, so thank you

regards
Pavel Stehule

> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


From: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Function with defval returns error
Date: 2008-12-19 04:14:57
Message-ID: 460abcb10812182014h1ff1fab6l8ba99990a4871207@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Dec 18, 2008 at 11:54 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com> writes:
> > Another issue found on CVS head ....
> > ...
> > postgres=> select f_test(10);
> > ERROR: cache lookup failed for type 2139062142
>
> I had some difficulty reproducing this locally. Would you check it's
> fixed by latest commit?

I did fast test and now it seems great. Thanks.

Regards,
Rushabh Lathia
www.Enterprisedb.com