---
title: keys() function
description: keys() returns the columns that are in the group key of each input table.
url: https://docs.influxdata.com/flux/v0/stdlib/universe/keys/
estimated_tokens: 2724
product: Flux
version: v0
---

# keys() function

-   Flux 0.13.0+
-   View InfluxDB support

`keys()` returns the columns that are in the group key of each input table.

Each output table contains a row for each group key column label. A single group key column label is stored in the specified `column` for each row. All columns not in the group key are dropped.

##### Function type signature

```js
(<-tables: stream[A], ?column: string) => stream[B] where A: Record, B: Record
```

For more information, see [Function type signatures](/flux/v0/function-type-signatures/).

## Parameters

### column

Column to store group key labels in. Default is `_value`.

### tables

Input data. Default is piped-forward data (`<-`).

## Examples

-   [Return group key columns for each input table](#return-group-key-columns-for-each-input-table)
-   [Return all distinct group key columns in a single table](#return-all-distinct-group-key-columns-in-a-single-table)
-   [Return group key columns as an array](#return-group-key-columns-as-an-array)

### Return group key columns for each input table

```js
data
    |> keys()
```

[](#view-example-input-and-output)

View example input and output

#### Input data

| *_field | *_measurement | *sensorID | _time | _value |
| --- | --- | --- | --- | --- |
| co | airSensors | TLM0100 | 2021-09-08T14:21:57Z | 0.31 |
| co | airSensors | TLM0100 | 2021-09-08T14:22:07Z | 0.295 |
| co | airSensors | TLM0100 | 2021-09-08T14:22:17Z | 0.314 |
| co | airSensors | TLM0100 | 2021-09-08T14:22:27Z | 0.313 |

| *_field | *_measurement | *sensorID | _time | _value |
| --- | --- | --- | --- | --- |
| humidity | airSensors | TLM0100 | 2021-09-08T14:21:57Z | 36.03 |
| humidity | airSensors | TLM0100 | 2021-09-08T14:22:07Z | 36.07 |
| humidity | airSensors | TLM0100 | 2021-09-08T14:22:17Z | 36.1 |
| humidity | airSensors | TLM0100 | 2021-09-08T14:22:27Z | 36.12 |

| *_field | *_measurement | *sensorID | _time | _value |
| --- | --- | --- | --- | --- |
| temperature | airSensors | TLM0100 | 2021-09-08T14:21:57Z | 70.84 |
| temperature | airSensors | TLM0100 | 2021-09-08T14:22:07Z | 70.86 |
| temperature | airSensors | TLM0100 | 2021-09-08T14:22:17Z | 70.89 |
| temperature | airSensors | TLM0100 | 2021-09-08T14:22:27Z | 70.85 |

#### Output data

| *_field | *_measurement | *sensorID | _value |
| --- | --- | --- | --- |
| co | airSensors | TLM0100 | _field |
| co | airSensors | TLM0100 | _measurement |
| co | airSensors | TLM0100 | sensorID |

| *_field | *_measurement | *sensorID | _value |
| --- | --- | --- | --- |
| humidity | airSensors | TLM0100 | _field |
| humidity | airSensors | TLM0100 | _measurement |
| humidity | airSensors | TLM0100 | sensorID |

| *_field | *_measurement | *sensorID | _value |
| --- | --- | --- | --- |
| temperature | airSensors | TLM0100 | _field |
| temperature | airSensors | TLM0100 | _measurement |
| temperature | airSensors | TLM0100 | sensorID |

### Return all distinct group key columns in a single table

```js
data
    |> keys()
    |> keep(columns: ["_value"])
    |> distinct()
```

[](#view-example-input-and-output)

View example input and output

#### Input data

| *_field | *_measurement | *sensorID | _time | _value |
| --- | --- | --- | --- | --- |
| co | airSensors | TLM0100 | 2021-09-08T14:21:57Z | 0.31 |
| co | airSensors | TLM0100 | 2021-09-08T14:22:07Z | 0.295 |
| co | airSensors | TLM0100 | 2021-09-08T14:22:17Z | 0.314 |
| co | airSensors | TLM0100 | 2021-09-08T14:22:27Z | 0.313 |

| *_field | *_measurement | *sensorID | _time | _value |
| --- | --- | --- | --- | --- |
| humidity | airSensors | TLM0100 | 2021-09-08T14:21:57Z | 36.03 |
| humidity | airSensors | TLM0100 | 2021-09-08T14:22:07Z | 36.07 |
| humidity | airSensors | TLM0100 | 2021-09-08T14:22:17Z | 36.1 |
| humidity | airSensors | TLM0100 | 2021-09-08T14:22:27Z | 36.12 |

| *_field | *_measurement | *sensorID | _time | _value |
| --- | --- | --- | --- | --- |
| temperature | airSensors | TLM0100 | 2021-09-08T14:21:57Z | 70.84 |
| temperature | airSensors | TLM0100 | 2021-09-08T14:22:07Z | 70.86 |
| temperature | airSensors | TLM0100 | 2021-09-08T14:22:17Z | 70.89 |
| temperature | airSensors | TLM0100 | 2021-09-08T14:22:27Z | 70.85 |

#### Output data

| _value |
| --- |
| _field |
| _measurement |
| sensorID |

### Return group key columns as an array

1. Use `keys()` to replace the `_value` column with the group key labels.
2. Use `findColumn()` to return the `_value` column as an array.

```js
import "sampledata"

sampledata.int()
    |> keys()
    |> findColumn(fn: (key) => true, column: "_value")// Returns [tag]

```

#### Related

-   [InfluxQL – SHOW MEASUREMENTS](/influxdb/v1/query_language/explore-schema/#show-measurements)
-   [InfluxQL – SHOW FIELD KEYS](/influxdb/v1/query_language/explore-schema/#show-field-keys)
-   [InfluxQL – SHOW TAG KEYS](/influxdb/v1/query_language/explore-schema/#show-tag-keys)
-   [InfluxQL – SHOW SERIES](/influxdb/v1/query_language/explore-schema/#show-tag-keys)

[transformations](/flux/v0/tags/transformations/)
