passing null parameter to plpgsq functions

From: "Picard, Cyril" <cyril(dot)picard(at)eads-dsn(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: passing null parameter to plpgsq functions
Date: 2001-04-03 07:00:26
Message-ID: B5CDCF382265D311BF33009027A8FE9401E6F365@pmrmsg.edsn.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello
I wrote a plpgsql function with few parameters ; when I call the function,
some of the parameters can be null.
In this case, all the parameters are considered as null in the function's
body ! is it a feature ? how can I work around this ?

Example :
CREATE FUNCTION foo(text, text) RETURNS bool AS '
begin
IF ($1 IS NULL) AND ($2 IS NULL) THEN
RETURN FALSE;
ELSE
RETURN TRUE;
END IF;
end;
' LANGUAGE 'plpgsql';

SELECT foo(null,'bouh') => false (I expected true)
SELECT foo('schfk',null) => false (I expected true)
SELECT foo(null,null) => false (OK)
SELECT foo('schfk','bouh') => true (OK)

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2001-04-03 08:03:02 Re: Appropriate indices to create for these queries
Previous Message Gerald Gutierrez 2001-04-03 01:49:44 Appropriate indices to create for these queries