Re: Null function parameters

Поиск
Список
Период
Сортировка
От tolik@aaanet.ru (Anatoly K. Lasareff)
Тема Re: Null function parameters
Дата
Msg-id 86ya1o8ak9.fsf@tolikus.hq.aaanet.ru
обсуждение исходный текст
Ответ на Null function parameters  ("Graham Vickrage" <graham@digitalplanit.com>)
Ответы RE: Null function parameters
Список pgsql-sql
>>>>> "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 then any>> values passed into the function that are null would be treated as 'NULL'.
 
TL> Not sure what you think you meant by that, but a null is a null.  If youTL> declared the table column as NOT NULL
thenPostgres 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 which caseTL> 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? |

Example.

create function a(int, int) returns int as '
begin raise notice ''1: % 2: %'', $1, $2;
 if $1 is null then   return $2; end if;
 return $1;
end;
' language 'plpgsql';

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

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


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


В списке pgsql-sql по дате отправления:

Предыдущее
От: hlefebvre
Дата:
Сообщение: Re: Date of creation and of change
Следующее
От: "Graham Vickrage"
Дата:
Сообщение: RE: Using SETOF in plpgsql function