From: | Tatsuo Ishii <ishii(at)sraoss(dot)co(dot)jp> |
---|---|
To: | guofenglinux(at)gmail(dot)com |
Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: Questionable coding in nth_value |
Date: | 2023-05-06 10:04:30 |
Message-ID: | 20230506.190430.556969896725622909.t-ishii@sranhm.sra.co.jp |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
> On Sat, May 6, 2023 at 4:44 PM Tatsuo Ishii <ishii(at)sraoss(dot)co(dot)jp> wrote:
>
>> Currently Window function nth_value is coded as following:
>>
>> nth = DatumGetInt32(WinGetFuncArgCurrent(winobj, 1, &isnull));
>> if (isnull)
>> PG_RETURN_NULL();
>> const_offset = get_fn_expr_arg_stable(fcinfo->flinfo, 1);
>>
>> if (nth <= 0)
>> ereport(ERROR,
>> :
>> :
>>
>> Is there any reason why argument 'nth' is not checked earlier?
>> IMO, it is more natural "if (nth <= 0)..." is placed right after "nth =
>> DatumGetInt32...".
>>
>> Attached is the patch which does this.
>
>
> Hmm, shouldn't we check if the argument of nth_value is null before we
> check if it is greater than zero? So maybe we need to do this.
That makes sense. I thought since this function is marked as strict,
it would not be called if argument is NULL, but I was wrong.
Best reagards,
--
Tatsuo Ishii
SRA OSS LLC
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp
From | Date | Subject | |
---|---|---|---|
Next Message | Joe Conway | 2023-05-06 10:55:55 | Re: Bancolombia Open Source Program Office - Proposal of contribution on lock inactive users |
Previous Message | Tatsuo Ishii | 2023-05-06 09:35:34 | Re: Add RESPECT/IGNORE NULLS and FROM FIRST/LAST options |