select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

FUNCTIONS / ARRAY FUNCTIONS AND OPERATORS

array_positions

Read PG 18 manual ↗

Returns an array of the subscripts of all occurrences of the second argument in the array given as first argument.

Signatures & examples

array_positions ( anycompatiblearray, anycompatible ) → integer[]
Returns an array of the subscripts of all occurrences of the second argument in the array given as first argument. The array must be one-dimensional. Comparisons are done using IS NOT DISTINCT FROM semantics, so it is possible to search for NULL. NULL is returned only if the array is NULL; if the value is not found in the array, an empty array is returned.
array_positions(ARRAY['A','A','B','A'], 'A') → {1,2,4}
Version history 3
  1. PG 13 → 14changed
  2. PG 12 → 13changed
  3. PG 9.4 → 9.5added

Definition snapshot: 2026-09-14T13:14:25.684213+00:00@99e6866c · English manual source