In Snowflake, I can get the first element of an array without knowing its length:
with foo as (
select array_construct('duck','duck','goose') as a
)
select a[0] from foo -- returns 'duck'
But to get the last element I can't use the "pythonic" a[-1], because select a[-1] from foo returns:
Invalid extraction path '-1': array index -1 is off limits; must be between 0 and 2,147,483,647.
Interestingly, I can use array_slice() to get the next-to-last element:
select array_slice(a,-2,-1) from foo -- returns 'duck'
but not the last element, since "the output includes elements up to, but not including the element specfied [sic] by the parameter" (doc).
How do I get the 'goose'?