ARRAY_PREPEND

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Inserts a value at the start of an array.

Syntax 

1ARRAY_PREPEND(<value>, <array>)

Arguments 

Required 

  • <value>: The value to insert at the start of the array. The value must match the array element type.
  • <array>: The array to prepend to.

Returns 

Returns an array with the new value inserted at the beginning.

Considerations 

  • Prepending NULL changes the array element type to nullable.

Examples 

Prepend a Value 

Add a value to the front of an array.

1SELECT ARRAY_PREPEND(1, array[2, 3, 4]) AS result;

Returns array[1, 2, 3, 4], with 1 inserted at the beginning.

Prepend NULL 

Add a NULL value to the front of an array.

1SELECT ARRAY_PREPEND(null, array[2, 3, 4]) AS result;

Returns array[null, 2, 3, 4]. Prepending NULL to an array with a non-nullable element type changes the resulting element type to nullable.

Related Documentation 

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!