I have this query written in Legacy SQL:
select
nth(1, a) first_a,
nth(1, b) first_b
from (
select *
from
(select 12 a, null b),
(select null a, 54 b)
)
As a result I was expecting one row with values (12, null), but I got (12, 54) instead. In the documentation for NTH it says:
NTH(n, field)
Returns the nth sequential value in the scope of the function, where n is a constant. The NTH function starts counting at 1, so there is no zeroth term. If the scope of the function has less than n values, the function returns NULL.
There is nothing indicating that nulls would be ignored. Is this a bug in BigQuery?