Re: Function with default value not replacing old definition of the function - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: Function with default value not replacing old definition of the function
Date
Msg-id 162867790812102310j4cb7a0e5ycea09704fcdcac9b@mail.gmail.com
Whole thread Raw
In response to Function with default value not replacing old definition of the function  ("Rushabh Lathia" <rushabh.lathia@gmail.com>)
Responses Re: Function with default value not replacing old definition of the function  ("Rushabh Lathia" <rushabh.lathia@gmail.com>)
Re: Function with default value not replacing old definition of the function  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hello

2008/12/11 Rushabh Lathia <rushabh.lathia@gmail.com>:
> Hi,
>
> Testcase: (8.4 CVS head)
> ====================
>
> CREATE OR REPLACE FUNCTION myfunc(y int)
> RETURNS INTEGER AS $$
>    select  100;
> $$ language sql;
>
> CREATE OR REPLACE FUNCTION myfunc(y int, x integer DEFAULT 100)
> RETURNS INTEGER AS $$
>    select  200;
> $$ language sql;
>
> select myfunc(10);
>
>  myfunc
> ----------
>       100
> (1 row)

no, it's little bit different

Default is only stored parameter value. You created two functions with
two different signatures

myfunc(int)
myfunc(int, int)

when you created function, we cannot check defaults, because we don't
know if anybody use default or not. And when you call function, then
postgres prefer function with most similar function.

regards
Pavel Stehule

>
> When create the same function again by added one default value, while
> calling the function old function getting called.
>
> It seems that, function with defval not making any sense, if we want to call
> the new function then we need to pass defval as well.
>
> select myfunc(10,10);
>
>  myfunc
> ----------
>       200
> (1 row)
>
> I think second function should replace the old definition of the function,
> inputs ?
>
>
> Thanks,
> Rushabh Lathia
> www.EnterpriseDB.com
>


pgsql-hackers by date:

Previous
From: "Rushabh Lathia"
Date:
Subject: Re: Function with default value not replacing old definition of the function
Next
From: MUHAMMAD ASIF
Date:
Subject: Re: PLUGINS Functionlity in Win32 build scripts