Re: Windowing Function Patch Review -> NTH_VALUE - Mailing list pgsql-hackers

From Hitoshi Harada
Subject Re: Windowing Function Patch Review -> NTH_VALUE
Date
Msg-id e08cc0400811110809o3fb66e4cu50350c70a3732b20@mail.gmail.com
Whole thread Raw
In response to Re: Windowing Function Patch Review -> NTH_VALUE  ("Hitoshi Harada" <umi.tanuki@gmail.com>)
Responses Re: Windowing Function Patch Review -> NTH_VALUE  ("Hitoshi Harada" <umi.tanuki@gmail.com>)
List pgsql-hackers
2008/11/10 Hitoshi Harada <umi.tanuki@gmail.com>:
> 2008/11/9 David Rowley <dgrowley@gmail.com>:
>> I'm having a little trouble understanding the standard for NTH_VALUE(). I
>> would have assumed that NTH_VALUE(name,1) would return the first name in the
>> window. The current patch is using 0 for the first.
>>
>
> Hmmm, good point... I haven't thought about it enough, just followed
> the internal design. The window_seek() in nodeWindow.c, which is an
> internal API, counts rows from 0 so the external behavior is simlar.
> Nothing more :-P
>

Reading the spec more closely, it says:

If <window function type> is <nth value function>, then:
i) Let RN be the value of <nth row>.
ii) Case:
1) If RN is the null value, then the result is the null value.
2) If RN is less than or equal to 0 (zero), then an exception
condition is raised: data exception ― invalid argument for NTH_VALUE
function.

So obviously nth_value(expr, 0) causes error and nth_value(expr, 1)
returns the first row. I will update my patch soon.

Regards,

-- 
Hitoshi Harada


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: pg_upgrade project status
Next
From: Zdenek Kotala
Date:
Subject: Re: pg_upgrade project status