Help needed with insert float into a text field!

I am trying to store multiple sources into the same table, with a column that is a text field.
When i try to insert a float into a text field, i get an error message saying that its a text field!

I would like to know:

  1. when will the ::string cast feature be added to influxdb? This way i can cast the float before inserting into a text field.
  2. why not just insert to float into the text field, without giving an error?

I hope someone can help me :smiley:

How are you writing the points? If you’re using line protocol directly, then instead of foo x=3.14 surround the value with double quotes, i.e. foo x="3.14".

We’ve chosen to prefer type safety over implicit type coercion. There are some functions that work on floats and integers but not strings (e.g. mean, sum). Rather than silently coercing your float data to a string field just to find that you later can’t perform the mathematical operations that you need, we decided to reject the write.

I have broken down the commands we use to fill the data:

INFLUXDB_URL=http://influxdb/write?db=database"

metric1="table1,mytag=tagname mystringvalue=string"
echo metric1 | curl -s -m 10 -i -XPOST $INFLUXDB_URL --data-binary @-

metric2="table2,mytag=tagname myfloatvalue=1024"
echo metric2 | curl -s -m 10 -i -XPOST $INFLUXDB_URL --data-binary @-

Continuous queries:
CREATE CONTINUOUS QUERY cq_metric1 ON database BEGIN 
  SELECT mytag AS mytag,
         mystringvalue AS myvalue
  FROM database."default".table1
  INTO database."default".finaltable
  GROUP BY time(1d)
END

CREATE CONTINUOUS QUERY cq_metric2 ON database BEGIN 
  SELECT mytag AS mytag,
         myfloatvalue AS myvalue
  FROM database."default".table2
  INTO database."default".finaltable
  GROUP BY time(1d)
END

And the problem is with the seconds continuous query with inserting myfloatvalue
But if i understand you correctly, i have to do this:

metric1="table1,mytag=tagname mystringvalue=\"string\""
metric2="table2,mytag=tagname myfloatvalue=\"1024\""

That’s right. If you want to use a CQ to insert a float value into a string field, you’ll need to store the original value as a string in the first place.

I briefly looked for open issues about casting value to string and I didn’t see one.

It might be possible to cast a float to a string in Kapacitor, but I’m not sure.

This works :grin:

echo 'zmm_compliance_raw,mytag=tagname mystringvalue="string"' | curl -s -m 10 -i -XPOST $INFLUXDB_URL --data-binary @-
echo 'zmm_compliance_raw,mytag=tagname myfloatvalue="1"' | curl -s -m 10 -i -XPOST $INFLUXDB_URL --data-binary @-

name: zmm_compliance_raw
------------------------
time                    myfloatvalue    mystringvalue   mytag  
1498717345732364450                     string          tagname
1498717513326394316     1                               tagname

SELECT mytag as mytag, mystringvalue as myvalue INTO puppet."default".zmm_compliance_daily FROM puppet."default".zmm_compliance_raw
SELECT mytag as mytag, myfloatvalue  as myvalue INTO puppet."default".zmm_compliance_daily FROM puppet."default".zmm_compliance_raw

name: zmm_compliance_daily
--------------------------
time                    mytag   myvalue
1498717345732364450     tagname string
1498717513326394316     tagname 1