---
title: tickscript.select() function
description: tickscript.select() changes a column’s name and optionally applies an aggregate or selector function to values in the column.
url: https://docs.influxdata.com/flux/v0/stdlib/contrib/bonitoo-io/tickscript/select/
estimated_tokens: 1942
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/stdlib/contrib/bonitoo-io/tickscript/select/
date: '2024-04-08T16:01:02-06:00'
lastmod: '2024-04-08T16:01:02-06:00'
---

* Flux 0.111.0+

InfluxDB support

> [!Important]
> `tickscript.select()` is a user-contributed function maintained by
> the [package author](#package-author-and-maintainer).

`tickscript.select()` changes a column’s name and optionally applies an aggregate or selector
function to values in the column.

## TICKscript helper function

`tickscript.select()` is a helper function meant to replicate TICKscript operations like the following:

```
// Rename
query("SELECT x AS y")

// Aggregate and rename
query("SELECT f(x) AS y")
```

##### Function type signature

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

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

## Parameters

### column

Column to operate on. Default is `_value`.

### fn

Aggregate or selector function to apply.

### as

(Required)
New column name.

### tables

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

## Examples

* [Change the name of the value column](#change-the-name-of-the-value-column)
* [Change the name of the value column and apply an aggregate function](#change-the-name-of-the-value-column-and-apply-an-aggregate-function)
* [Change the name of the value column and apply a selector function](#change-the-name-of-the-value-column-and-apply-a-selector-function)

### Change the name of the value column

```js
import "contrib/bonitoo-io/tickscript"
import "sampledata"

sampledata.int()
    |> tickscript.select(as: "example-name")
```

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

View example input and output

#### Input data

|       \_time       |\_value|\*tag|
|--------------------|-------|-----|
|2021-01-01T00:00:00Z|  \-2  | t1  |
|2021-01-01T00:00:10Z|  10   | t1  |
|2021-01-01T00:00:20Z|   7   | t1  |
|2021-01-01T00:00:30Z|  17   | t1  |
|2021-01-01T00:00:40Z|  15   | t1  |
|2021-01-01T00:00:50Z|   4   | t1  |

|       \_time       |\_value|\*tag|
|--------------------|-------|-----|
|2021-01-01T00:00:00Z|  19   | t2  |
|2021-01-01T00:00:10Z|   4   | t2  |
|2021-01-01T00:00:20Z|  \-3  | t2  |
|2021-01-01T00:00:30Z|  19   | t2  |
|2021-01-01T00:00:40Z|  13   | t2  |
|2021-01-01T00:00:50Z|   1   | t2  |

#### Output data

|       \_time       |example-name|\*tag|
|--------------------|------------|-----|
|2021-01-01T00:00:00Z|    \-2     | t1  |
|2021-01-01T00:00:10Z|     10     | t1  |
|2021-01-01T00:00:20Z|     7      | t1  |
|2021-01-01T00:00:30Z|     17     | t1  |
|2021-01-01T00:00:40Z|     15     | t1  |
|2021-01-01T00:00:50Z|     4      | t1  |

|       \_time       |example-name|\*tag|
|--------------------|------------|-----|
|2021-01-01T00:00:00Z|     19     | t2  |
|2021-01-01T00:00:10Z|     4      | t2  |
|2021-01-01T00:00:20Z|    \-3     | t2  |
|2021-01-01T00:00:30Z|     19     | t2  |
|2021-01-01T00:00:40Z|     13     | t2  |
|2021-01-01T00:00:50Z|     1      | t2  |

### Change the name of the value column and apply an aggregate function

```js
import "contrib/bonitoo-io/tickscript"
import "sampledata"

sampledata.int()
    |> tickscript.select(as: "sum", fn: sum)
```

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

View example input and output

#### Input data

|       \_time       |\_value|\*tag|
|--------------------|-------|-----|
|2021-01-01T00:00:00Z|  \-2  | t1  |
|2021-01-01T00:00:10Z|  10   | t1  |
|2021-01-01T00:00:20Z|   7   | t1  |
|2021-01-01T00:00:30Z|  17   | t1  |
|2021-01-01T00:00:40Z|  15   | t1  |
|2021-01-01T00:00:50Z|   4   | t1  |

|       \_time       |\_value|\*tag|
|--------------------|-------|-----|
|2021-01-01T00:00:00Z|  19   | t2  |
|2021-01-01T00:00:10Z|   4   | t2  |
|2021-01-01T00:00:20Z|  \-3  | t2  |
|2021-01-01T00:00:30Z|  19   | t2  |
|2021-01-01T00:00:40Z|  13   | t2  |
|2021-01-01T00:00:50Z|   1   | t2  |

#### Output data

|\*tag|sum|
|-----|---|
| t1  |51 |

|\*tag|sum|
|-----|---|
| t2  |53 |

### Change the name of the value column and apply a selector function

```js
import "contrib/bonitoo-io/tickscript"
import "sampledata"

sampledata.int()
    |> tickscript.select(as: "max", fn: max)
```

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

View example input and output

#### Input data

|       \_time       |\_value|\*tag|
|--------------------|-------|-----|
|2021-01-01T00:00:00Z|  \-2  | t1  |
|2021-01-01T00:00:10Z|  10   | t1  |
|2021-01-01T00:00:20Z|   7   | t1  |
|2021-01-01T00:00:30Z|  17   | t1  |
|2021-01-01T00:00:40Z|  15   | t1  |
|2021-01-01T00:00:50Z|   4   | t1  |

|       \_time       |\_value|\*tag|
|--------------------|-------|-----|
|2021-01-01T00:00:00Z|  19   | t2  |
|2021-01-01T00:00:10Z|   4   | t2  |
|2021-01-01T00:00:20Z|  \-3  | t2  |
|2021-01-01T00:00:30Z|  19   | t2  |
|2021-01-01T00:00:40Z|  13   | t2  |
|2021-01-01T00:00:50Z|   1   | t2  |

#### Output data

|       \_time       |max|\*tag|
|--------------------|---|-----|
|2021-01-01T00:00:30Z|17 | t1  |

|       \_time       |max|\*tag|
|--------------------|---|-----|
|2021-01-01T00:00:00Z|19 | t2  |

#### Related

* [tickscript.selectWindow() function](/flux/v0/stdlib/contrib/bonitoo-io/tickscript/selectwindow/)

[transformations](/flux/v0/tags/transformations/)
| _time | _value | *tag |
| --- | --- | --- |
| _time | _value | *tag |
| 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:10Z | 10 | t1 |
| 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:50Z | 4 | t1 |

| _time | _value | *tag |
| --- | --- | --- |
| _time | _value | *tag |
| 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:10Z | 4 | t2 |
| 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:50Z | 1 | t2 |

| _time | example-name | *tag |
| --- | --- | --- |
| _time | example-name | *tag |
| 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:10Z | 10 | t1 |
| 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:50Z | 4 | t1 |

| _time | example-name | *tag |
| --- | --- | --- |
| _time | example-name | *tag |
| 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:10Z | 4 | t2 |
| 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:50Z | 1 | t2 |

| _time | _value | *tag |
| --- | --- | --- |
| _time | _value | *tag |
| 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:10Z | 10 | t1 |
| 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:50Z | 4 | t1 |

| _time | _value | *tag |
| --- | --- | --- |
| _time | _value | *tag |
| 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:10Z | 4 | t2 |
| 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:50Z | 1 | t2 |

| *tag | sum |
| --- | --- |
| *tag | sum |
| t1 | 51 |

| *tag | sum |
| --- | --- |
| *tag | sum |
| t2 | 53 |

| _time | _value | *tag |
| --- | --- | --- |
| _time | _value | *tag |
| 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:10Z | 10 | t1 |
| 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:50Z | 4 | t1 |

| _time | _value | *tag |
| --- | --- | --- |
| _time | _value | *tag |
| 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:10Z | 4 | t2 |
| 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:50Z | 1 | t2 |

| _time | max | *tag |
| --- | --- | --- |
| _time | max | *tag |
| 2021-01-01T00:00:30Z | 17 | t1 |

| _time | max | *tag |
| --- | --- | --- |
| _time | max | *tag |
| 2021-01-01T00:00:00Z | 19 | t2 |
