> For the complete documentation index, see [llms.txt](https://upsolver.gitbook.io/content/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://upsolver.gitbook.io/content/reference-1/functions-and-operators/functions/comparison/least.md).

# LEAST

This function returns the smallest of the provided values.

## Syntax

```sql
LEAST(VALUE1 [, VALUE2, ..., VALUEN]) 
```

## Arguments

#### **`VALUE`**

Type: `double`, `bigint`, `string`, `timestamp`, `date`, `array`

A value of any of the above types, provided that all values are of the same type.

## Returns

Type: same as input

The smallest of the provided values.

When the input values are arrays, the smallest element between all the arrays is returned.

If any of the input values are `null`, the result is `null` as well.

***

## Examples

### Transformation job example

#### SQL

```sql
CREATE JOB function_operator_example
    ADD_MISSING_COLUMNS = true	
AS INSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data 
  MAP_COLUMNS_BY_NAME
    SELECT 
        LEAST(3.4, 66.0, 744.7) AS least_example1,
        LEAST('a', 'z', 'h', 'k') AS least_example2,
        LEAST(date '2022-08-14', date '2022-02-05', null::date) AS least_example3
    FROM default_glue_catalog.upsolver_samples.orders_raw_data 
    WHERE $commit_time BETWEEN run_start_time() AND run_end_time()
    LIMIT 1;
```

#### Query result

| least\_example1 | least\_example2 | least\_example3 |
| --------------- | --------------- | --------------- |
| 3.4             | a               | null            |

### Example with arrays

#### SQL

```sql
CREATE JOB function_operator_example
    ADD_MISSING_COLUMNS = true	
AS INSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data 
        MAP_COLUMNS_BY_NAME
    SELECT 
        LEAST(ARRAY[1.1, 0.2], ARRAY[3.0]) AS least_example1,
        LEAST(ARRAY[1.1, 0.2], ARRAY[3.0, null::double]) AS least_example2,
        LEAST([1.1, 0.2], [3.0], [null::double]) AS least_example3
    FROM default_glue_catalog.upsolver_samples.orders_raw_data 
    WHERE $commit_time BETWEEN run_start_time() AND run_end_time()
    LIMIT 1;
```

#### Query result

| least\_example1 | least\_example2 | least\_example3 |
| --------------- | --------------- | --------------- |
| 0.2             | 0.2             | null            |

Note that `least_example3` evaluates to `null` since the array containing only `null` is considered a null value.

For arrays containing null and non-null values, Upsolver ignores those null values when working with the array. For example, `least_example2` evaluates to `0.2` instead of `null`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://upsolver.gitbook.io/content/reference-1/functions-and-operators/functions/comparison/least.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
