SLICE

All functions > ARRAY > SLICE

Returns a slice of an array with optional step parameter.

Syntax

SLICE(array, start, length[, step])
sql

Arguments

ParameterTypeRequiredDescription
arrayARRAYBIGINTYesThe input array to slice
startBIGINTYesStarting position (1-based indexing, negative for end-relative)
lengthBIGINTNoNumber of elements to extract
stepBIGINTNoStep size for element selection (default: 1)

Returns

A new array containing the specified slice of elements

Notes

  • Uses 1-based indexing (SQL standard)
  • Negative start values count from the end of the array
  • Optional length parameter specifies how many elements to extract
  • Optional step parameter allows extracting every nth element
  • Step can be negative for reverse traversal
  • Returns empty array if start is out of bounds

Aliases

  • ARRAY_SLICE

  • LIST_SLICE

Examples

Basic Slicing

Negative Indices

Step Parameter

Negative Step

Last update at: 2025/10/13 10:23:46