insert_item

Description

Returns an array containing all elements from the source array as well as the new element.

The new element is inserted at position idx. The original element from this position (if any) and all subsequent elements (if any) are shifted by one position to the right in the resulting array. The length of the array increases by one item.

A negative position is interpreted as an index from the back of the array (e.g. -1 results in insertion before the last element in the array).

Return type

array

Domain

This is a scalar function (calculates a single output value for a single input row.)

Categories

Usage

insert_item(arr, idx, val)

Argument

Type

Optional

Repeatable

Restrictions

arr

array

no

no

none

idx

int64

no

no

none

val

variant

no

no

none

Examples

make_col foo:array(parse_json('[1,2,4]'))
make_col bar:insert_item(foo, 2, 3)
// foo
// [1,2,3,4]

Inserts the integer 3 into the array in column foo at index 2 (zero-based index). The result is stored in column bar.