Re: Function Parameters - need help !!! - Mailing list pgsql-sql

From Richard Huxton
Subject Re: Function Parameters - need help !!!
Date
Msg-id 40D6CC7B.7090606@archonet.com
Whole thread Raw
In response to Re: Function Parameters - need help !!!  ("Pradeepkumar, Pyatalo (IE10)" <Pradeepkumar.Pyatalo@honeywell.com>)
List 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


pgsql-sql by date:

Previous
From: "Phil Endecott"
Date:
Subject: Re: Function Parameters - need help !!!
Next
From: Tom Lane
Date:
Subject: Re: subselect prob in view