Skip to content

InsertAt

mapping category: array no `||` new-mode: required resultSize: 1

Inserts a scalar value at the given 0-based index of an ARRAY, returning a new ARRAY.

InsertAt(N, value) inserts a scalar at position N of the input array; existing elements at and after N shift one position right. The index is clamped to [0, size]: negative values insert at the front, indices beyond the end append at the back.

The pipeline must carry a single ARRAY-typed value; the rule produces a new ARRAY of length size + 1.

Available in new mode only.

Parameters

1index Mandatory — accepts: INT

Insertion position. Clamped to [0, size] — negative indices insert at the front, indices beyond the end append.

2value Mandatory — accepts: BOOLEAN, DATE, FLOAT, INT, STRING, NULL

A scalar literal to insert. ARRAY values and field references are not accepted.

Input type

  • ARRAY

Output type

  • ARRAY

Requires

  • Exactly one ARRAY-typed pipeline input.

Examples

Insert a header element at the front (test095)

Use(:a, :b, :c)[3] => InsertAt(0, "first")

Append by passing the array's length

Use(:a, :b)[2] => InsertAt(99, "appended")

Errors

  • `InsertAt': input must be ARRAY-typed
    The pipeline value reaching the rule is not an ARRAY.
  • `InsertAt' requires two parameters: an integer index and a scalar value
    Wrong arity, non-integer index, or non-scalar value.
  • `InsertAt' second parameter must be a scalar value
    An ARRAY literal or unknown-type expression was used as the value parameter.
  • `InsertAt' is only available in new mode
    New mode is not enabled in etl.conf.

See also

At, RemoveAt, ReplaceAt, Append, Size