Re: Returning NULL from functions

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Returning NULL from functions
Дата
Msg-id 1160.1000955474@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Returning NULL from functions  (Thomas Lockhart <lockhart@fourpalms.org>)
Список pgsql-hackers
Thomas Lockhart <lockhart@fourpalms.org> writes:
> ERROR:  OidFunctionCall3: function 1150 returned NULL

> Is this error message a feature of all returns of NULL, particular to
> input routines, or can I somehow mark routines as being allowed to
> return NULL values?

It's a "feature" for all places that invoke SQL functions via the
FooFunctionCallN routines.  The API for those routines offers no way
to handle passing or returning NULL, so they have little choice but to
raise elog(ERROR) if they see the called function return NULL.

Those routines are intended for use in places where a NULL result is
nonsensical anyway, and so extending their API to allow NULL would just
create useless notational clutter.  If you want to cope with NULLs then
you have to set up and inspect a FunctionCallInfoData structure for
yourself.  See the comments in backend/utils/fmgr/fmgr.c.

Offhand I see no good reason why a datatype input routine should return
NULL.  Either return a valid value of the type, or elog(ERROR).  IMHO,
NULL is (and should be) an out-of-band value handled by
datatype-independent logic.
        regards, tom lane


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: type casting troubles
Следующее
От: Thomas Lockhart
Дата:
Сообщение: Re: type casting troubles