Re: Function sugnature with default parameter - Mailing list pgsql-hackers

From David Johnston
Subject Re: Function sugnature with default parameter
Date
Msg-id 1393439496691-5793739.post@n5.nabble.com
Whole thread Raw
In response to Function sugnature with default parameter  (salah jubeh <s_jubeh@yahoo.com>)
List pgsql-hackers
salah jubeh wrote
> Hello,
>
> I find default values confusing when a function is overloaded, below is an
> example.
>
>
> CREATE OR REPLACE FUNCTION default_test (a INT DEFAULT 1, b INT DEFAULT 1,
> C INT DEFAULT 1) RETURNS INT AS
> $$
>     BEGIN
>         RETURN a+b+c;
>     END;
> $$
> LANGUAGE 'plpgsql';

Provide a real use-case for this need and maybe someone will consider it
worthwhile to implement.

In the meantime use VARIADIC or define only the longest-default signature
and provide reasonable default values for all optional arguments.  In this
case the defaults should be zero, not one.

Or don't make any of the arguments DEFAULT and provide as many overloads as
you use.  The whole point of DEFAULT was to avoid having to do this for
simple cases - you are not compelled to use default values if your use-case
is too complex for them.

Or just avoid overloading and use different names that describe better what
the different versions accomplish.

Specifying "DEFAULT" in the function call seems to defeat the point.

David J.




--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Function-sugnature-with-default-parameter-tp5793737p5793739.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Changeset Extraction v7.7
Next
From: Andres Freund
Date:
Subject: Re: Changeset Extraction v7.7