# Transform \<a field\>=\<a value\> into field=\<a field\> value=\<a value\>

**URL:** <https://community.influxdata.com/t/transform-a-field-a-value-into-field-a-field-value-a-value/31656>\
**Category:** Telegraf\
**Created:** [September 29, 2023, 12:21pm UTC](https://community.influxdata.com/t/transform-a-field-a-value-into-field-a-field-value-a-value/31656 "2023-09-29T12:21:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![poesel](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@poesel](https://community.influxdata.com/u/poesel)\
**Post date:** [September 29, 2023, 12:21pm UTC](https://community.influxdata.com/t/transform-a-field-a-value-into-field-a-field-value-a-value/31656/1 "2023-09-29T12:21:24Z")

</div>

Hi,

this looks quite simple, but I couldn’t find the right plugin.

I have this line:

```auto
Converter,host=23d86d9833d1,type=TF,zone=01 Frequency=401i,Quality="OK (0x0)" 1695986031000000000

```

and I want to convert it to:

```auto
Converter,host=23d86d9833d1,type=TF,zone=01 measurement="Frequency",value=401i,Quality="OK (0x0)" 1695986031000000000

```

So that I get two columns in my database instead of one.

How do I do that? Thanks!

---

<div class="post-metadata">

**Author:** ![jpowers](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jpowers/32/8569_2.png) [@jpowers](https://community.influxdata.com/u/jpowers)\
**Post date:** [September 29, 2023, 1:29pm UTC](https://community.influxdata.com/t/transform-a-field-a-value-into-field-a-field-value-a-value/31656/2 "2023-09-29T13:29:52Z")

</div>

> [@poesel](#):
>
> ```auto
> So that I get two columns in my database instead of one.
> 
> ```

This is what the unpivot processor does:

```toml
[[processors.unpivot]]
  tag_key = "measurement"
  value_key = "value"

```

Transforms

```auto
Converter,host=23d86d9833d1,type=TF,zone=01 Frequency=401i,Quality="OK (0x0)" 1695986031000000000

```

to

```auto
Converter,host=23d86d9833d1,measurement=Frequency,type=TF,zone=01 value=401i 1695986031000000000
Converter,host=23d86d9833d1,measurement=Quality,type=TF,zone=01 value="OK (0x0)" 1695986031000000000

```

Of course, that did that to both fields, Frequency and Quality. Also note the measurement value, because it is a string, becomes a tag. You can covert it back to a field if you need it to be a field instead.

If you know the names of the fields you want to do this with, you could also do it with the starlark processor.

---

<div class="post-metadata">

**Author:** ![poesel](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@poesel](https://community.influxdata.com/u/poesel)\
**Post date:** [September 29, 2023, 5:32pm UTC](https://community.influxdata.com/t/transform-a-field-a-value-into-field-a-field-value-a-value/31656/3 "2023-09-29T17:32:18Z")

</div>

Thanks for the answer, but that is not what I need.

First, we can ignore the quality value. This comes from an OPC UA input and could be filtered out.  
The target output is TimescaleDB (via Postgres)

This line:

```auto
Converter,host=23d86d9833d1,measurement=Frequency,type=TF,zone=01 value=401i

```

would give me a tag ‘measurement’, but what I need is a field ‘measurement’ (both with the value ‘Frequency’).

The additional tag is a problem because the Timescale output creates a unique tag\_id from it. But I have other values (like ‘Current’) that need to have the same ID. So I can’t have that additional tag.

---

<div class="post-metadata">

**Author:** ![jpowers](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jpowers/32/8569_2.png) [@jpowers](https://community.influxdata.com/u/jpowers)\
**Post date:** [September 29, 2023, 7:07pm UTC](https://community.influxdata.com/t/transform-a-field-a-value-into-field-a-field-value-a-value/31656/4 "2023-09-29T19:07:44Z")

</div>

> [@poesel](#):
>
> would give me a tag ‘measurement’, but what I need is a field ‘measurement’ (both with the value ‘Frequency’).

As I mentioned above, you can then convert it back.

---

<div class="post-metadata">

**Author:** ![poesel](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@poesel](https://community.influxdata.com/u/poesel)\
**Post date:** [September 29, 2023, 7:34pm UTC](https://community.influxdata.com/t/transform-a-field-a-value-into-field-a-field-value-a-value/31656/5 "2023-09-29T19:34:35Z")

</div>

> [@jpowers](#):
>
> `Converter,host=23d86d9833d1,measurement=Frequency,type=TF,zone=01 value=401i`

Oh, I see. After ‘unpivot’ I run a ‘converter’ processor to convert the ‘measurement’ tag to a field of the same name. Ok, thanks.

Sorry, one last question: is it more efficient to run two processors like this or one starlark script that does the same?

Thanks!

---

<div class="post-metadata">

**Author:** ![jpowers](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jpowers/32/8569_2.png) [@jpowers](https://community.influxdata.com/u/jpowers)\
**Post date:** [September 29, 2023, 8:04pm UTC](https://community.influxdata.com/t/transform-a-field-a-value-into-field-a-field-value-a-value/31656/6 "2023-09-29T20:04:18Z")

</div>

> [@poesel](#):
>
> Oh, I see. After ‘unpivot’ I run a ‘converter’ processor to convert the ‘measurement’ tag to a field of the same name. Ok, thanks.

Exactly! I would also mention setting the “order” value in your config to ensure it runs afterwards, something like:

```toml
[[processors.unpivot]]
  order = 1
  tag_key = "measurement"
  value_key = "value"

[[processors.converter]]
  order = 2
  ...

```

> Sorry, one last question: is it more efficient to run two processors like this or one starlark script that does the same?

I would generally say using these processors is preferred over running starlark. Starlark has a bit of overhead.
