Re: Function Parameters - need help !!!

From: Richard Huxton <dev(at)archonet(dot)com>
To: "Pradeepkumar, Pyatalo (IE10)" <Pradeepkumar(dot)Pyatalo(at)honeywell(dot)com>
Cc: aspire420(at)hotpop(dot)com, pgsql-sql(at)postgresql(dot)org
Subject: Re: Function Parameters - need help !!!
Date: 2004-06-21 11:54:35
Message-ID: 40D6CC7B.7090606@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Pradeepkumar, Pyatalo (IE10) wrote:
> Well this is right for the local variables....but what about the function
> parameters. Okay, I will make it more simple....say I want to write a
> function like this....
>
> CREATE FUNCTION test(integer,integer) RETURNS INTEGER AS '
> DECLARE
> param1 ALIAS FOR $1;
> param2 ALIAS FOR $2;
> BEGIN
> -------
IF param1 IS NULL THEN
param1 := 1234;
END IF;

> Now i want to define default values to param1 and param2....if i dont pass a
> value....the function should take default values for those
> arguments.....that is what i was trying to implement....need help on this

Now if you want to be able to call function test like so:
SELECT test(1)
Then you can't.

The workaround is to define two functions:
CREATE FUNCTION test(integer,integer)
CREATE FUNCTION test(integer)
Function #2 calls function #1 with the 2nd paramter pre-defined.

PG is quite strict about it's type-matching, which is why you need to
have two entries for the function.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2004-06-21 14:19:43 Re: subselect prob in view
Previous Message Phil Endecott 2004-06-21 11:52:48 Re: Function Parameters - need help !!!