pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Pradeepkumar, Pyatalo (IE10) <Pradeepkumar.Pyatalo@honeywell.com>
Cc: aspire420@hotpop.com
Cc: pgsql-sql@postgresql.org
Subject: Re: Function Parameters - need help !!!
Date: Mon, 21 Jun 2004 12:54:35 +0100
Message-ID: <40D6CC7B.7090606@archonet.com> (raw)
In-Reply-To: <77ED2BF75D59D1439F90412CC5B109740DCFBDCC@ie10-sahara.hiso.honeywell.com>
References: <77ED2BF75D59D1439F90412CC5B109740DCFBDCC@ie10-sahara.hiso.honeywell.com>

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



view thread (5+ messages)

Message-ID: <40D6CC7B.7090606@archonet.com>
Permalink:  ../40D6CC7B.7090606@archonet.com/
Also on:    postgresql.org/message-id/40D6CC7B.7090606@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, Pradeepkumar.Pyatalo@honeywell.com, aspire420@hotpop.com
  Subject: Re: Function Parameters - need help !!!
  In-Reply-To: <40D6CC7B.7090606@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox