Array Functions

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Functions and operators for inspecting, accessing, and transforming array values. Use array functions to:

  • Access and inspect array elements by index or search for values.
  • Measure and analyze arrays by checking length and finding positions.
  • Modify and transform arrays by adding, removing, or deduplicating elements.
  • Perform vector operations for similarity searches on embeddings.

Considerations

  • 1-based indexing: Array indices start at 1, not 0.
  • Element types: Many functions require matching element types between arrays.
  • NULL handling: NULL elements are preserved unless explicitly removed with

For more information about supported types, see Array Type.

Access and Inspection

Access array elements and check for content:

Array Building

Create and build arrays:

Array Transformation

Sort, filter, and transform arrays:

Array Expansion

Expand an array into a set of rows:

  • unnest - Expand array elements into a set of rows.

Vector and Similarity

Perform vector operations for similarity searches on embeddings:

Examples

Filtering by Array Content

Find products with specific tags.

SELECT product_name
FROM products
WHERE array_contains(tags, 'sale');

Find products matching any search tag.

SELECT product_name
FROM products
WHERE array_contains_any(tags, array['new', 'featured', 'popular']);

Array Manipulation

Build a complete list by combining arrays.

SELECT array_cat(primary_categories, secondary_categories) AS all_categories
FROM products;

Clean up arrays by removing nulls and duplicates.

SELECT array_distinct(array_compact(values)) AS clean_values
FROM data;

Transforming Array Elements

Double every element using a lambda expression.

SELECT array_transform(array[1, 2, 3, 4], lambda x: x * 2) AS doubled;
-- Returns [2, 4, 6, 8]

Filter to keep only values above a threshold.

SELECT array_filter(array[10, 25, 5, 30, 15], lambda x: x > 20) AS large;
-- Returns [25, 30]

Vector Search

Find top five most similar products using embeddings

SELECT
    name,
    dot_product('[0.1, -0.2, 0.7, -0.3]'::REAL[], description_vec) AS score
FROM products
ORDER BY score DESC
LIMIT 5;

Related Documentation