ARRAY_PREPEND

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Inserts a value at the start of an array.

Syntax

array_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.

SELECT 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.

SELECT 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