> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TRY_ELEMENT_AT

> Returns an array element by position or a map value by key.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

NULL collection, NULL index/key or missing map key returns NULL. Out-of-bounds arrays return NULL for TRY\_ELEMENT\_AT; ELEMENT\_AT raises an error when ANSI mode is enabled, otherwise returns NULL.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
try_element_at(collection, index_or_key)
```

## Arguments

Type notation used below:

* T is the array element type: BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT.
* V is the map value type: BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT.

| Name | Type | Required | Description |
| - | - | - | - |
| collection | ARRAY\<T> or MAP\<K,V> | Yes | Collection to access. Nested elements/fields must satisfy the same element-type restrictions. K is the map key type: BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT. A lookup key must have the map's key type after conversion. Map keys must be non-NULL. Nested values retain their declared element/field types. |
| index\_or\_key | INTEGER for ARRAY; compatible key type for MAP | Yes | Array position or map key. |

## Returns

* Type: T for ARRAY; V for MAP
* NULL behavior: NULL collection, NULL index/key or missing map key returns NULL. Out-of-bounds arrays return NULL for TRY\_ELEMENT\_AT; ELEMENT\_AT raises an error when ANSI mode is enabled, otherwise returns NULL.
* Shape: One selected value per input row. For ARRAY\<T>, the result has the element type and shape T; for MAP\<K,V>, it has the value type and shape V. If that selected type is ARRAY, MAP or STRUCT, its nested contents and type are retained while the enclosing lookup collection is removed.
* Ordering: A returned nested ARRAY retains its element order, a returned MAP retains its entry order without adding a SQL key-order guarantee, and a returned STRUCT retains its field order. This scalar lookup does not impose SQL output row ordering.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Usage notes

* E6 and Databricks function-call indexing is one-based. Negative positions count from the end. Snowflake source context currently uses zero-based indexing.
* Index zero in a one-based ARRAY function call is invalid, including TRY\_ELEMENT\_AT; TRY only suppresses bounds failures.
* A nested ARRAY/MAP/STRUCT value is selected as a value of that type; this lookup does not flatten or re-sort its nested contents.
* INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
* Deterministic: The same inputs and settings produce the same result.

## Examples

### Typical behavior

* E6/Databricks source-dialect indexing.

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT try_element_at(ARRAY(10, 20, 30), 1) AS first_value, try_element_at(ARRAY(10, 20, 30), -1) AS last_value;
```

| first\_value | last\_value |
| - | - |
| 10 | 30 |

### Look up map keys

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT try_element_at(map('red', 10, 'blue', 20), 'blue') AS found, try_element_at(map('red', 10, 'blue', 20), 'green') AS missing;
```

| found | missing |
| - | - |
| 20 | NULL |

## Limitations

* Unsupported collection/index types can fail during planning.
* For map lookups, pass a MAP value. Unlike ELEMENT\_AT, TRY\_ELEMENT\_AT does not also accept maps represented as arrays of STRING-key entries.

## Related functions

* [get](/query/sql/functions/array/get)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.