Dela via


Funktionen array_position

Gäller för:markerad ja Databricks SQL markerad ja Databricks Runtime

Returnerar positionen för den första förekomsten av element i array.

Syntax

array_position(array, element)

Argument

  • array: En MATRIS med jämförbara element.
  • element: Ett uttryck som matchar typerna av elementen i array.

Returer

En BIGINT.

Matrisindexering börjar vid 1. Om elementvärdet är NULLreturneras en NULL. Om elementet inte hittas i matrisen returneras ett 0.

Exempel

-- 1 exists twice. The function returns the first position
> SELECT array_position(array(3, 2, 1, 4, 1), 1);
 3

-- this function cannot be used to find the position of a NULL element.
> SELECT array_position(array(3, NULL, 1), NULL)
 NULL

> SELECT array_position(array(3, 2, 1), NULL)
 NULL

-- The element is not found in the array
> SELECT array_position(array(3, 2, 1, 4, 1), 5)
 0