Removes the first element from an array. The function returns a new array containing all elements from the original array except the first one.
array_popfront(ARRAY<T> arr)
arr:ARRAY type, the array from which to remove the first elementSupported types for T:
Return type: ARRAY
Return value meaning:
Usage notes:
Query Examples:
Remove the first element from a string array:
SELECT array_popfront(['apple', 'banana', 'cherry', 'date']); +----------------------------------------------------+ | array_popfront(['apple', 'banana', 'cherry', 'date']) | +----------------------------------------------------+ | ["banana", "cherry", "date"] | +----------------------------------------------------+
Remove the first element from an array containing null values:
SELECT array_popfront([1, null, 3, null, 5]); +------------------------------------------+ | array_popfront([1, null, 3, null, 5]) | +------------------------------------------+ | [null, 3, null, 5] | +------------------------------------------+
Arrays with only one element return empty arrays:
SELECT array_popfront([42]); +------------------------+ | array_popfront([42]) | +------------------------+ | [] | +------------------------+
Empty arrays return empty arrays:
SELECT array_popfront([]); +------------------------+ | array_popfront([]) | +------------------------+ | [] | +------------------------+
NULL arrays return NULL:
SELECT array_popfront(NULL); +------------------------+ | array_popfront(NULL) | +------------------------+ | NULL | +------------------------+
Remove the first element from an IP address array:
SELECT array_popfront(CAST(['192.168.1.1', '192.168.1.2', '192.168.1.3'] AS ARRAY<IPV4>)); +----------------------------------------------------------------------------------+ | array_popfront(CAST(['192.168.1.1', '192.168.1.2', '192.168.1.3'] AS ARRAY<IPV4>)) | +----------------------------------------------------------------------------------+ | ["192.168.1.2", "192.168.1.3"] | +----------------------------------------------------------------------------------+
Remove the first element from a nested array:
SELECT array_popfront([[1, 2], [3, 4], [5, 6]]); +------------------------------------------+ | array_popfront([[1, 2], [3, 4], [5, 6]]) | +------------------------------------------+ | [[3, 4], [5, 6]] | +------------------------------------------+
Remove the first element from a MAP array:
SELECT array_popfront([{'name':'Alice','age':20}, {'name':'Bob','age':30}, {'name':'Charlie','age':40}]); +------------------------------------------------------------------------------------------+ | array_popfront([{'name':'Alice','age':20}, {'name':'Bob','age':30}, {'name':'Charlie','age':40}]) | +------------------------------------------------------------------------------------------+ | [{"name":"Bob","age":30}, {"name":"Charlie","age":40}] | +------------------------------------------------------------------------------------------+
Remove the first element from a STRUCT array:
SELECT array_popfront(array(named_struct('name','Alice','age',20), named_struct('name','Bob','age',30), named_struct('name','Charlie','age',40))); +-------------------------------------------------------------------------------------------------------------------------------------------+ | array_popfront(array(named_struct('name','Alice','age',20), named_struct('name','Bob','age',30), named_struct('name','Charlie','age',40))) | +-------------------------------------------------------------------------------------------------------------------------------------------+ | [{"name":"Bob", "age":30}, {"name":"Charlie", "age":40}] | +-------------------------------------------------------------------------------------------------------------------------------------------+
ARRAY, POPFRONT, ARRAY_POPFRONT