---
title: vector_l2_distance function
description: Learn the syntax of the vector\_l2\_distance function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/vector_l2_distance
---

# `vector_l2_distance` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 18.1 and above

Computes the Euclidean (L2) distance between two vectors.

## Syntax

```
vector_l2_distance(vector1, vector2)
```

## Arguments

* **vector1**: An `ARRAY<FLOAT>` expression representing the first vector.
* **vector2**: An `ARRAY<FLOAT>` expression representing the second vector.

## Returns

A `FLOAT` value representing the Euclidean distance between the two vectors. The result is non-negative, where 0.0 indicates identical vectors.

Returns 0.0 for empty vectors. Returns `NULL` if either input is `NULL` or contains `NULL`.

## Notes

* Only `ARRAY<FLOAT>` is supported; other types such as `ARRAY<DOUBLE>` or `ARRAY<DECIMAL>` raise an error.
* Both vectors must have the same dimension; otherwise the function raises [VECTOR\_DIMENSION\_MISMATCH](https://docs.databricks.com/aws/en/error-messages/error-classes.md#vector_dimension_mismatch).
* Lower values indicate greater similarity (closer vectors); also known as Euclidean distance.

## Error conditions

* [VECTOR\_DIMENSION\_MISMATCH](https://docs.databricks.com/aws/en/error-messages/error-classes.md#vector_dimension_mismatch)

## Examples

```sql
-- Basic L2 distance
> SELECT vector_l2_distance(array(1.0f, 2.0f, 3.0f), array(4.0f, 5.0f, 6.0f));
  5.196152422706632

-- Distance between identical vectors
> SELECT vector_l2_distance(array(1.0f, 2.0f), array(1.0f, 2.0f));
  0.0

-- Classic 3-4-5 triangle
> SELECT vector_l2_distance(array(0.0f, 0.0f), array(3.0f, 4.0f));
  5.0
```

## Related functions

* [`vector_norm` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/vector_norm.md)
* [`vector_cosine_similarity` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/vector_cosine_similarity.md)
* [`vector_inner_product` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/vector_inner_product.md)
* [`vector_normalize` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/vector_normalize.md)
