Обсуждение: [PATCH] Add error_on_null() to produce an error if the input is null

Поиск
Список
Период
Сортировка

[PATCH] Add error_on_null() to produce an error if the input is null

От
"Joel Jacobson"
Дата:
Dear fellow hackers,

This polymorphic function produces an error if the input value is null,
otherwise it returns the input value unchanged.

This need for this function originates from the discussion
"Assert single row returning SQL-standard functions" [1].

/Joel

[1] https://www.postgresql.org/message-id/flat/9233b657-696f-430f-9557-dc602a2b9e0e%40app.fastmail.com

Вложения

Re: [PATCH] Add error_on_null() to produce an error if the input is null

От
Vik Fearing
Дата:
On 30/08/2025 13:49, Joel Jacobson wrote:
> Dear fellow hackers,
>
> This polymorphic function produces an error if the input value is null,
> otherwise it returns the input value unchanged.


This only checks for the null value.  I don't think we need to change 
the function's name, but we do need to be more precise in the 
documentation that it checks for the null value and not values that are 
null.


Perhaps replacing "Produces an error if the input is null, and returns 
the input otherwise." with "Produces an error if the input is the null 
value, and returns the input otherwise."


Then also add ROW(NULL, NULL)) to the regressions tests showing that we 
are aware that that is the behavior for things that are null but are not 
the null value.

-- 

Vik Fearing




Re: [PATCH] Add error_on_null() to produce an error if the input is null

От
Tom Lane
Дата:
Vik Fearing <vik@postgresfriends.org> writes:
> On 30/08/2025 13:49, Joel Jacobson wrote:
>> This polymorphic function produces an error if the input value is null,
>> otherwise it returns the input value unchanged.

> This only checks for the null value.  I don't think we need to change 
> the function's name, but we do need to be more precise in the 
> documentation that it checks for the null value and not values that are 
> null.

Agreed.  You might be able to borrow some wording from the docs'
discussion of the IS [NOT] NULL construct, and/or IS DISTINCT FROM.

            regards, tom lane



Re: [PATCH] Add error_on_null() to produce an error if the input is null

От
"Joel Jacobson"
Дата:
On Sat, Aug 30, 2025, at 18:38, Tom Lane wrote:
> Vik Fearing <vik@postgresfriends.org> writes:
>> On 30/08/2025 13:49, Joel Jacobson wrote:
>>> This polymorphic function produces an error if the input value is null,
>>> otherwise it returns the input value unchanged.
>
>> This only checks for the null value.  I don't think we need to change 
>> the function's name, but we do need to be more precise in the 
>> documentation that it checks for the null value and not values that are 
>> null.
>
> Agreed.  You might be able to borrow some wording from the docs'
> discussion of the IS [NOT] NULL construct, and/or IS DISTINCT FROM.
>
>             regards, tom lane

Thanks for great feedback. New patch attached.

/Joel

Вложения

Re: [PATCH] Add error_on_null() to produce an error if the input is null

От
Vik Fearing
Дата:


On 31/08/2025 10:04, Joel Jacobson wrote:
Thanks for great feedback. New patch attached.


This new patch resolves all of my concerns and I think it is ready for committer.  Does it have a commitfest entry where I can make that official?

-- 

Vik Fearing

Re: [PATCH] Add error_on_null() to produce an error if the input is null

От
"Joel Jacobson"
Дата:
On Sun, Aug 31, 2025, at 15:54, Vik Fearing wrote:
> On 31/08/2025 10:04, Joel Jacobson wrote: 
>> Thanks for great feedback. New patch attached.
>
>
> This new patch resolves all of my concerns and I think it is ready for 
> committer.

Thanks for reviewing.

> Does it have a commitfest entry where I can make that 
> official?

Yes: https://commitfest.postgresql.org/patch/6017/

/Joel



Re: [PATCH] Add error_on_null() to produce an error if the input is null

От
Vik Fearing
Дата:


On 31/08/2025 16:10, Joel Jacobson wrote:
Does it have a commitfest entry where I can make that 
official?
Yes: https://commitfest.postgresql.org/patch/6017/


Thank you.  Updated.

-- 

Vik Fearing