> 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/array.md).

# Array

This section describes the following array functions:

<table><thead><tr><th width="284">Function</th><th>Description</th></tr></thead><tbody><tr><td><a href="/pages/5nBk2fMSX6S1gDGpZvkC">ARRAY_DISTINCT</a></td><td>Return all the distinct elements in the array.</td></tr><tr><td><a href="/pages/cRwd8HdvuMaKZlXispwq">ARRAY_JOIN</a></td><td>This function concatenates the elements of the given array to a string using the separator.</td></tr><tr><td><a href="/pages/ZZwS0bMmr2i5mLMbvPvU">ARRAY_MAX</a></td><td>Return the maximum value in an array.</td></tr><tr><td><a href="/pages/PE9uw57ypKTirdXuqt7u">ARRAY_MIN</a></td><td>Return the minimum value in an array.</td></tr><tr><td><a href="/pages/FA4QIEzsvT1DGuF1N6H2">ARRAY_SORT</a></td><td>Returns the values in the array in ascending order</td></tr><tr><td><a href="/pages/klvmperfy5W26JbGU6RI">ARRAY_SORT_DESC</a></td><td>Returns the values in the array in descending order</td></tr><tr><td><a href="/pages/Xb6zw9dtxxNRw08wt1VJ">ARRAY_SUM</a></td><td>This function calculates the sum of all non-null elements of the input. If there are no non-null elements, returns 0. The behavior is similar to aggregate function SUM, but operates on an array.</td></tr><tr><td><a href="/pages/9JgL47BioGGdziA222EK">COUNT_VALUES</a></td><td>Returns the amount of non-null items in a given array.</td></tr><tr><td><a href="/pages/Ec2f77bGnBKbsiNYLlYa">COUNT_VALUES_IF</a></td><td>Returns the amount of <code>true</code> values in a given array. This can be used with conditional operators to count the number of array elements that fulfil a condition. For example, <code>COUNT_VALUES_IF(my_values[] > 3)</code> will return the number of elements that are greater than 3.</td></tr><tr><td><a href="/pages/uVXXq7wmmNihn5OIJeB4">ELEMENT_AT</a></td><td>This function returns an element of an array at a given index. If index >= 0, this function provides the same functionality as the SQL-standard subscript operator ([]). If index &#x3C; 0, <code>ELEMENT_AT</code> accesses elements from the last to the first.</td></tr><tr><td><a href="/pages/gwotGMJPgIaC4owDrDRg">FIRST_ELEMENT</a></td><td>Returns the first element in the array.</td></tr><tr><td><a href="/pages/XXYzPoyeCzsZwRhRittT">LAST_ELEMENT</a></td><td>Returns the last element in the array.</td></tr><tr><td><a href="/pages/xN4VBfetafJaPUSWTXp4">VALUE_INDEX_IN_ARRAY</a></td><td>Calculates a 1-based positional index for each non-null value within a sub-array, resetting the index with each new sub-array. </td></tr><tr><td><a href="/pages/5i1Zr2gr92xHjvWclvnJ">VALUE_INDEX_IN_ROW</a></td><td>Calculates a continuous, 1-based positional index for each value in an array, treating the entire row as a single context. It assigns a unique index to each non-null element across the arrays within the row.</td></tr></tbody></table>


---

# 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/array.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.
