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

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Reply via email to