Skip to content

Latest commit

 

History

History
13 lines (10 loc) · 411 Bytes

get-last-array-element.md

File metadata and controls

13 lines (10 loc) · 411 Bytes

Get the last element of an array

Explore this snippet here.

Description

There are two methods to retrieve the last element of an array - calculate the array length, or reverse the array and select the first element:

select 
  nums[ordinal(array_length(nums))] as method_1,
  array_reverse(nums)[ordinal(1)] as method_2,
from (select [1, 2, 3, 4] as nums)