X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 42888D1B1CF for ; Mon, 21 Jun 2004 08:54:42 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63647-04 for ; Mon, 21 Jun 2004 11:54:42 +0000 (GMT) Received: from anchor-post-34.mail.demon.net (anchor-post-34.mail.demon.net [194.217.242.92]) by svr1.postgresql.org (Postfix) with ESMTP id C5A6BD1B1C8 for ; Mon, 21 Jun 2004 08:54:37 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-34.mail.demon.net with esmtp (Exim 3.35 #1) id 1BcNNn-000AKQ-0Y; Mon, 21 Jun 2004 12:54:40 +0100 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 25E1115911; Mon, 21 Jun 2004 12:54:36 +0100 (BST) Message-ID: <40D6CC7B.7090606@archonet.com> Date: Mon, 21 Jun 2004 12:54:35 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 0.7 (X11/20040615) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Pradeepkumar, Pyatalo (IE10)" Cc: aspire420@hotpop.com, pgsql-sql@postgresql.org Subject: Re: Function Parameters - need help !!! References: <77ED2BF75D59D1439F90412CC5B109740DCFBDCC@ie10-sahara.hiso.honeywell.com> In-Reply-To: <77ED2BF75D59D1439F90412CC5B109740DCFBDCC@ie10-sahara.hiso.honeywell.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.3 tagged_above=0.0 required=5.0 tests=PLING_PLING X-Spam-Level: * X-Archive-Number: 200406/194 X-Sequence-Number: 18139 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