> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify-poc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# into_values()

> Returns the highest values and associated data from a MaxNBy aggregate

<Icon icon="tag" iconType="duotone" /> Since [1.16.0][toolkit-1.16.0]

This returns the largest values seen by the aggregate and the
corresponding values associated with them. Note that Postgres requires
an input argument with type matching the associated value in order to
determine the response type.

## Samples

Find the top 5 values from i \* 13 % 10007 for i = 1 to 10000:

```sql theme={"dark"}
SELECT into_values(
    max_n_by(sub.mod, sub.div, 5),
    NULL::INT)
FROM (
  SELECT (i * 13) % 10007 AS mod, (i * 13) / 10007 AS div
  FROM generate_series(1,10000) as i
) sub;
```

Output:

```
into_values
-------------
(10006,3)
(10005,7)
(10004,11)
(10003,2)
(10002,6)
```

## Arguments

The syntax is:

```sql theme={"dark"}
into_values(
  agg MaxNBy,
  dummy ANYELEMENT
) TABLE (
  value BIGINT | DOUBLE PRECISION | TIMESTAMPTZ,
  data ANYELEMENT
)
```

| Name    | Type       | Default | Required | Description                                                                                                      |
| ------- | ---------- | ------- | -------- | ---------------------------------------------------------------------------------------------------------------- |
| `agg`   | MaxNBy     | -       | ✔        | The aggregate to return the results from. Note that the exact type here varies based on the type of data stored. |
| `dummy` | ANYELEMENT | -       | ✔        | This is purely to inform Postgres of the response type. A NULL cast to the appropriate type is typical.          |

## Returns

| Column       | Type                                                        | Description                                            |
| ------------ | ----------------------------------------------------------- | ------------------------------------------------------ |
| into\_values | SETOF BIGINT \| SETOF DOUBLE PRECISION \| SETOF TIMESTAMPTZ | The highest values seen while creating this aggregate. |

[toolkit-1.16.0]: https://github.com/timescale/timescaledb-toolkit/releases/tag/1.16.0
