Skip site navigation (1) Skip section navigation (2)

RE: Null function parameters

From: "Graham Vickrage" <graham(at)digitalplanit(dot)com>
To: "Anatoly K(dot) Lasareff" <tolik(at)aaanet(dot)ru>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "postgresql" <pgsql-sql(at)postgresql(dot)org>
Subject: RE: Null function parameters
Date: 2000-08-23 12:07:31
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
Thanks Anatoly

So if I understand you correctly you can't pass more than one NULL int into
a function?

Therefore Newbe DBA type question: -
Is this a shortcoming in postgres or is it to be expected when dealing with
If it is a shotcoming are there any plans to include it in future releases?



-----Original Message-----
From: tolik(at)tolikus(dot)hq(dot)aaanet(dot)ru [mailto:tolik(at)tolikus(dot)hq(dot)aaanet(dot)ru]On
Behalf Of Anatoly K. Lasareff
Sent: 23 August 2000 12:46
To: Tom Lane
Cc: Graham Vickrage; postgresql
Subject: Re: [SQL] Null function parameters

>>>>> "TL" == Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

 TL> "Graham Vickrage" <graham(at)digitalplanit(dot)com> writes:
 >> However my understanding was that if the default value is SQL NULL then
 >> values passed into the function that are null would be treated as

 TL> Not sure what you think you meant by that, but a null is a null.  If
 TL> declared the table column as NOT NULL then Postgres is doing exactly
 TL> 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 which
 TL> value2".

 TL> regards, tom lane

But unfortunately we have no answer for primary question:

| Why if we pass to function ONLY ONE null agument all the oters    |
| argumenta in function's boby are null too?                        |
| Or: is it possible to pass null arguments into plpgsql functions? |


create function a(int, int) returns int as '
  raise notice ''1: % 2: %'', $1, $2;

  if $1 is null then
    return $2;
  end if;

  return $1;
' language 'plpgsql';

tolik=# select a(1,2);
NOTICE:  1: 1 2: 2
(1 row)

tolik=# select a(null,2);
NOTICE:  1: <NULL> 2: <NULL>

(1 row)

Anatoly K. Lasareff              Email:       tolik(at)aaanet(dot)ru

In response to


pgsql-sql by date

Next:From: Graham VickrageDate: 2000-08-23 12:15:16
Subject: RE: Using SETOF in plpgsql function
Previous:From: Anatoly K. LasareffDate: 2000-08-23 11:46:14
Subject: Re: Null function parameters

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group