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

# VALUE\_INDEX\_IN\_ROW

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.

## Syntax

```sql
VALUE_INDEX_IN_ROW(array)
```

## Arguments

#### **`array`**

Type: any

An array of any value types.

***

## Example

### Transformation job example

In this example, the **orders** column contains the following two rows:

{% code overflow="wrap" fullWidth="false" %}

```sql
[{"products":[{"name":"Apple"},{"name":"Banana"}]},{"products":[{"name":"Cherry"},{"name":"Cherry"}]}]
[{"products":[{"name":"Apple","type":"Fruit"},{"name":"Banana"}]},{"products":[{"name":"Cherry"},{"name":"Cherry"},{"type":"Berry"}]}]
```

{% endcode %}

If we use this in the following job, it will output the query result below:

### Transformation job example

### SQL

{% code overflow="wrap" %}

```sql
CREATE JOB index_products
   RUN_INTERVAL = 1 MINUTE
   START_FROM = BEGINNING
   ADD_MISSING_COLUMNS = TRUE
AS INSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data
  MAP_COLUMNS_BY_NAME
   SELECT
    *,
    VALUE_INDEX_IN_ROW(orders[].products[].name) AS orders[].products[].name_index,
    VALUE_INDEX_IN_ROW(orders[].products[].type) AS orders[].products[].type_index
  FROM default_glue_catalog.upsolver_samples.orders_raw_data 
  WHERE time_filter();
```

{% endcode %}

#### Query result

The function `VALUE_INDEX_IN_ROW` ("name\_index") returns a unique index for each **name** field within the row, regardless of which **products** object it belongs to, and the `VALUE_INDEX_IN_ROW` ("type\_index") returns a unique index for the **type** field.&#x20;

Now the value of **orders** is:

{% code overflow="wrap" %}

```
[{"products":
[{"name":"Apple","name_index":1},{"name":"Banana","name_index":2}]},{"products":[{"name":"Cherry","name_index":3},{"name":"Cherry","name_index":4}]
}]
[{"products":
[{"name":"Apple","name_index":1,"type":"Fruit","type_index":1},"name":"Banana","name_index":2}]},{"products":[{"name":"Cherry","name_index":3},{"name":"Cherry","name_index":4},{"type":"Berry","type_index":2}]
}]
```

{% endcode %}

`VALUE_INDEX_IN_ROW` calculates the positional index of the value in the context of its own row by\
assigning the value to the same array containing the items we index. In the above example, where we have **products** inside **orders**), it will assign a unique index for each **name** and **type**.&#x20;

Two similar rows have been added in order to demonstrate the behavior of nulls in records that don’t contain **type**.

The index is agnostic to the specific **products** object in which the **name** and **type** field is found, and provides a continuous count of  **name** and **type** fields within the row. We can think of it as a global index in the row.


---

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