---
title: schema.fieldsAsCols() function
description: schema.fieldsAsCols() is a special application of pivot() that pivots input data on _field and _time columns to align fields within each input table that have the same timestamp.
url: https://docs.influxdata.com/flux/v0/stdlib/influxdata/influxdb/schema/fieldsascols/
estimated_tokens: 697
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/stdlib/influxdata/influxdb/schema/fieldsascols/
date: '2024-04-08T16:01:02-06:00'
lastmod: '2024-04-08T16:01:02-06:00'
---

* Flux 0.88.0+

InfluxDB support

`schema.fieldsAsCols()` is a special application of `pivot()` that pivots input data
on `_field` and `_time` columns to align fields within each input table that
have the same timestamp.

##### Function type signature

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

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

## Parameters

### tables

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

## Examples

### Pivot InfluxDB fields into columns

```js
import "influxdata/influxdb/schema"

data
    |> schema.fieldsAsCols()
```

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

View example input and output

#### Input data

|       \_time       |\*\_measurement| \*loc |\*\_field|\_value|
|--------------------|---------------|-------|---------|-------|
|2021-01-01T12:00:00Z|       m       |Seattle|   hum   | 89.2  |
|2021-01-02T12:00:00Z|       m       |Seattle|   hum   | 90.5  |
|2021-01-03T12:00:00Z|       m       |Seattle|   hum   | 81.0  |

|       \_time       |\*\_measurement| \*loc |\*\_field|\_value|
|--------------------|---------------|-------|---------|-------|
|2021-01-01T12:00:00Z|       m       |Seattle|  temp   | 73.1  |
|2021-01-02T12:00:00Z|       m       |Seattle|  temp   | 68.2  |
|2021-01-03T12:00:00Z|       m       |Seattle|  temp   | 61.4  |

#### Output data

|       \_time       |\*\_measurement| \*loc |hum |temp|
|--------------------|---------------|-------|----|----|
|2021-01-01T12:00:00Z|       m       |Seattle|89.2|73.1|
|2021-01-02T12:00:00Z|       m       |Seattle|90.5|68.2|
|2021-01-03T12:00:00Z|       m       |Seattle|81.0|61.4|

#### Not supported in the Flux REPL

`schema` functions can retrieve schema information when executed within
the context of InfluxDB, but not from the [Flux REPL](/influxdb/cloud/tools/repl/).

[transformations](/flux/v0/tags/transformations/)
| _time | *_measurement | *loc | *_field | _value |
| --- | --- | --- | --- | --- |
| _time | *_measurement | *loc | *_field | _value |
| 2021-01-01T12:00:00Z | m | Seattle | hum | 89.2 |
| 2021-01-02T12:00:00Z | m | Seattle | hum | 90.5 |
| 2021-01-03T12:00:00Z | m | Seattle | hum | 81.0 |

| _time | *_measurement | *loc | *_field | _value |
| --- | --- | --- | --- | --- |
| _time | *_measurement | *loc | *_field | _value |
| 2021-01-01T12:00:00Z | m | Seattle | temp | 73.1 |
| 2021-01-02T12:00:00Z | m | Seattle | temp | 68.2 |
| 2021-01-03T12:00:00Z | m | Seattle | temp | 61.4 |

| _time | *_measurement | *loc | hum | temp |
| --- | --- | --- | --- | --- |
| _time | *_measurement | *loc | hum | temp |
| 2021-01-01T12:00:00Z | m | Seattle | 89.2 | 73.1 |
| 2021-01-02T12:00:00Z | m | Seattle | 90.5 | 68.2 |
| 2021-01-03T12:00:00Z | m | Seattle | 81.0 | 61.4 |
