How to solve type conflicts

influxdb

#1

Hi,

I‘m using the influxdb-php lib to read from and write to influx. I haven‘t thought much of it in the beginning and just started to import date into the db, which worked fine. But later when I added some importers, I stumbled over type conflict issues like that:
write failed: field type conflict: input field "value" on measurement "temp" is type integer, already exists as type float

So it seems that the first value I inserted was interpreted as a float (even though it doesn‘t need to be one), which resulted in that type.
Now I always need type cast to float (which I forget pretty often when implementing a new importer) even though in this measurement only integer values will be added.

Additionally the query show field keys from temp returns this:

fieldKey fieldType
-------- ---------
value    float
value    integer

So two types for one field? It is just confusing.

The question is now: is there any way to “repair” this, so that a) there is only one type which b) is integer?

Thanks for your help!


#2

There’s a good explanation in the docs.


#3

Thanks for your help!

So, if I get this straight: there is nothing much I can do about it, but maybe migrating all the values of a specific type to a new measurement. Right?


#4

You can (should?) force the type when you insert (certainly the first time). You can put an i after the value to force an integer.

What you can do now is copy the data to a new measurement, drop the old one, then copy the data back. Be sure to use the group by when copying to a new measurement to preserve your tags.


#5

Hi inselbuch, thanks for the reply! :slight_smile:

Well, the problem is that, as far as I know, with the PHP infliux library you can‘t force a datatype, but it tries to find the best matching type for the set value. The only thing around it is to really type cast before putting it into the library. And this is the whole issue I have: I forgot to do it once, and now have two different datatypes in the measurement, but even though float and integer are available the insert call throws these data type errors. So I don‘t really see where this second data type comes from, but would be fine with it if it would mean that I can add integers AND floats.

That is what I thought of in regards of fixing it. To bad, that there is no simpler way. But thanks for the tip! :slight_smile: