Re: Null function parameters - Mailing list pgsql-sql

From tolik@aaanet.ru (Anatoly K. Lasareff)
Subject Re: Null function parameters
Date
Msg-id 86em3gumhr.fsf@tolikus.hq.aaanet.ru
Whole thread Raw
In response to RE: Null function parameters  ("Graham Vickrage" <graham@digitalplanit.com>)
Responses Re: Null function parameters  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
>>>>> "GV" == Graham Vickrage <graham@digitalplanit.com> writes:
GV> Thanks AnatolyGV> So if I understand you correctly you can't pass more than one NULL int intoGV> a function?

I'afraid no. My question is: if I pass one null argument into function
then all
other argumens, which are not null, became null inside function body.







GV> Therefore Newbe DBA type question: -GV> Is this a shortcoming in postgres or is it to be expected when dealing
withGV>transactions?GV> If it is a shotcoming are there any plans to include it in future releases?
 
GV> Regards
GV> Graham
GV> -----Original Message-----GV> From: tolik@tolikus.hq.aaanet.ru [mailto:tolik@tolikus.hq.aaanet.ru]OnGV> Behalf Of
AnatolyK. LasareffGV> Sent: 23 August 2000 12:46GV> To: Tom LaneGV> Cc: Graham Vickrage; postgresqlGV> Subject: Re:
[SQL]Null function parameters
 


>>>>> "TL" == Tom Lane <tgl@sss.pgh.pa.us> writes:
TL> "Graham Vickrage" <graham@digitalplanit.com> writes:>>> However my understanding was that if the default value is
SQLNULL thenGV> any>>> values passed into the function that are null would be treated asGV> 'NULL'.
 
TL> Not sure what you think you meant by that, but a null is a null.  IfGV> youTL> declared the table column as NOT
NULLthen Postgres is doing exactlyTL> what it should.  You may wish to code the insert along the lines of
 
TL> INSERT INTO table VALUES (..., COALESCE($1, suitable-default), ...)
TL> COALESCE is a handy notation for "value1 unless it's NULL, in whichGV> caseTL> value2".
TL> regards, tom lane
GV> But unfortunately we have no answer for primary question:
GV> | Why if we pass to function ONLY ONE null agument all the oters    |GV> | argumenta in function's boby are null
too?                       |GV> | Or: is it possible to pass null arguments into plpgsql functions? |
 
GV> Example.
GV> create function a(int, int) returns int as 'GV> beginGV> raise notice ''1: % 2: %'', $1, $2;
GV> if $1 is null thenGV> return $2;GV> end if;
GV> return $1;GV> end;GV> ' language 'plpgsql';
GV> tolik=# select a(1,2);GV> NOTICE:  1: 1 2: 2GV> aGV> ---GV> 1GV> (1 row)
GV> tolik=# select a(null,2);GV> NOTICE:  1: <NULL> 2: <NULL>GV> aGV> ---
GV> (1 row)

-- 
Anatoly K. Lasareff              Email:       tolik@aaanet.ru 


pgsql-sql by date:

Previous
From: Jan Wieck
Date:
Subject: Re: Using SETOF in plpgsql function
Next
From: Karel Zak
Date:
Subject: Re: Using SETOF in plpgsql function