# Problem getting Integer and float into DB

**URL:** <https://community.influxdata.com/t/problem-getting-integer-and-float-into-db/28249>\
**Category:** Telegraf\
**Created:** [January 20, 2023, 7:36am UTC](https://community.influxdata.com/t/problem-getting-integer-and-float-into-db/28249 "2023-01-20T07:36:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shadowblues](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Shadowblues](https://community.influxdata.com/u/Shadowblues)\
**Post date:** [January 20, 2023, 7:36am UTC](https://community.influxdata.com/t/problem-getting-integer-and-float-into-db/28249/1 "2023-01-20T07:36:16Z")

</div>

Hi,  
I am quite new to that topic. I am trying since days to sort that out but I can’t find the right syntax.  
I have values in my MQTT server:

```auto
PWR_MPII = 14
PWR_L1 = 576.7000122070312
PWR_L2 = 466.6000061035156
PWR_L3 = 2283.39990234375
PWR_SB5-1 = 0
PWR_SB5-2 = 0
PWR_SBS5 = 0

```

Sometimes the L1, L2, L3 values are without decimal points.

So I have integer and float values.

I tried the following code to import them:

```auto
[[inputs.mqtt_consumer]]
  name_override = "mqtt_home"
  servers = ["tcp://myip:1883"]
  topics = [
     "victron/PWR_L1",
     "victron/PWR_L2",
     "victron/PWR_L3",
  ]
  qos = 0
  connection_timeout = "60s"
  max_undelivered_messages = 1
  persistent_session = false
  client_id = "telegraf_victron_mqtt"
  username = "xxx"
  password = "xxx"
  data_format = "value"
  data_type = "float"   
  interval = "5s"
    [inputs.mqtt_consumer.tags]
      destination = "Victron_bucket"

[[inputs.mqtt_consumer]]
  name_override = "mqtt_home"
  servers = ["tcp://myip:1883"]
  topics = [
     "victron/PWR_MPII",
     "victron/PWR_SB5-1",
     "victron/PWR_SB5-2",
     "victron/PWR_SBS5",
  ]
  qos = 0
  connection_timeout = "60s"
  max_undelivered_messages = 1
  persistent_session = false
  client_id = "telegraf_victron_mqtt2"
  username = xxx"
  password = "xxx"
  data_format = "value"
  data_type = "integer"   
  interval = "5s"
    [inputs.mqtt_consumer.tags]
      destination = "Victron_bucket"

```

Unfortunately this still throws errors:

```auto
2023-01-20T07:26:09Z I! [inputs.mqtt_consumer] Connected [tcp://myip:1883]
2023-01-20T07:26:09Z I! [inputs.mqtt_consumer] Connected [tcp://myip:1883]
2023-01-20T07:26:19Z E! [outputs.influxdb_v2] When writing to [http://myip:8086]: 500 Internal Server Error: internal error: unexpected error writing points to database: field type conflict
2023-01-20T07:26:19Z E! [agent] Error writing to outputs.influxdb_v2: failed to send metrics to any configured server(s)
2023-01-20T07:26:29Z E! [outputs.influxdb_v2] Failed to write metric to Victron_bucket (will be dropped: 422 Unprocessable Entity): unprocessable entity: failure writing points to database: partial write: field type conflict: input field "value" on measurement "mqtt_home" is type integer, already exists as type float dropped=1

```

I tried with type conversion and deleted the data values in the bucket completey - but I don’t get it to work.

Can someone please help me? 🙂

---

<div class="post-metadata">

**Author:** ![Giovanni\_Luisotto](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/giovanni_luisotto/32/4017_2.png) [@Giovanni\_Luisotto](https://community.influxdata.com/u/Giovanni_Luisotto)\
**Post date:** [January 20, 2023, 10:06am UTC](https://community.influxdata.com/t/problem-getting-integer-and-float-into-db/28249/2 "2023-01-20T10:06:07Z")

</div>

Can we have some sample output?

You just need to write to a file in influx format, or to run telegraf with the `--test` option which will output the data in the console.

My understanding is that you are writing data from both mqtt inputs in the same measurement (mqtt\_home) with the same filed key (value), and a field must have only one datatype (enforced at shard level). Why don’t you just write everything as float?

---

<div class="post-metadata">

**Author:** ![Shadowblues](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Shadowblues](https://community.influxdata.com/u/Shadowblues)\
**Post date:** [January 20, 2023, 10:59am UTC](https://community.influxdata.com/t/problem-getting-integer-and-float-into-db/28249/3 "2023-01-20T10:59:18Z")

</div>

I don\*t know what you mean with output?

If I start it with the --test option, then it shows me:

```auto
2023-01-20T10:50:52Z I! Starting Telegraf 1.25.0
2023-01-20T10:50:52Z I! Available plugins: 228 inputs, 9 aggregators, 26 processors, 21 parsers, 57 outputs, 2 secret-stores
2023-01-20T10:50:52Z I! Loaded inputs: mqtt_consumer (2x)
2023-01-20T10:50:52Z I! Loaded aggregators:
2023-01-20T10:50:52Z I! Loaded processors:
2023-01-20T10:50:52Z I! Loaded secretstores:
2023-01-20T10:50:52Z W! Outputs are not used in testing mode!
2023-01-20T10:50:52Z I! Tags enabled: host=srv-lnx-hometools
2023-01-20T10:50:52Z I! [inputs.mqtt_consumer] Connected [tcp://myip:1883]
2023-01-20T10:50:52Z I! [inputs.mqtt_consumer] Connected [tcp://myip:1883]

```

Everything as float would be ok for me. However, when I try this, he will just skip the integer values.  
But if I only have the config with the integer values, then they land in the DB.

I am not writing the same values since that are different keys. But ok, I changes that mqtt\_home value in one instance and it worked instantly. Thank you!

So the data type is defined at that level?

---

<div class="post-metadata">

**Author:** ![Giovanni\_Luisotto](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/giovanni_luisotto/32/4017_2.png) [@Giovanni\_Luisotto](https://community.influxdata.com/u/Giovanni_Luisotto)\
**Post date:** [January 20, 2023, 11:07am UTC](https://community.influxdata.com/t/problem-getting-integer-and-float-into-db/28249/4 "2023-01-20T11:07:33Z")

</div>

let’s pretend a measurement is equivalent to a table in a SQL DB… each column must have a unique name and a datatype…

In InfluxDB the “columns” are tags and fields, tags are string only, fields can have a bunch of datatypes but a single field can only have one… having mixed datatypes is an issue that can happen since this is not enforced globally but by shard, meaning that in the first value inserted (in a new shard) will define that “column” datatype

---

<div class="post-metadata">

**Author:** ![Shadowblues](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Shadowblues](https://community.influxdata.com/u/Shadowblues)\
**Post date:** [January 20, 2023, 11:58am UTC](https://community.influxdata.com/t/problem-getting-integer-and-float-into-db/28249/5 "2023-01-20T11:58:36Z")

</div>

Thank you for the information 🙂 This explains the wasted hours 🙂
