How do you INSERT into influxDB using the SQL-like interface? - influxdb

Is it possible to INSERT data into series / measurements using the SQL-like interface on InfluxDB?

Yes, you can simply INSERT a Line Protocol string.
An example from Getting Started:
INSERT cpu,host=serverA,region=us_west value=0.64
A point with the measurement name of cpu and tags host and region has now been written to the database, with the measured value of 0.64.

Related

Synapse Serverless - Other than String_agg,for Xml to convert row to column

I'm using Synapse Serverless and I want to convert row to Column. Use STRING_AGG but due to nvarchar(8000) limitation I was getting error "STRING_AGG aggregation result exceeded the limit of 8000 bytes. Use LOB types to avoid result truncation" due to that I tried to rtecreate the Query with XML path and Stuff but Serverless wont support. Is there any workaround?
The error STRING_AGG aggregation result exceeded the limit of 8000 bytes. Use LOB types to avoid result truncation has a workaround. The STRING_AGG has a limit of 8000 bytes by default, but when it exceeds this limit, you can change the limit to nvarchar(max) or varchar(max) using CONVERT inside STRING_AGG.
Refer to the following link to know how to do the above conversion and understand more information about STRING_AGG with CONVERT.
https://www.mssqltips.com/sqlservertutorial/9371/sql-string-agg-function/
There is a relational operator called PIVOT which conventionally helps to transform rows data into columns (UNPIVOT operator is also available- does the exact opposite of what PIVOT does). The following is a syntax of PIVOT:
SELECT (ColumnNames)
FROM (TableName)
PIVOT
(
AggregateFunction(ColumnToBeAggregated)
FOR PivotColumn IN (PivotColumnValues)
) AS (Alias)
Refer to the following link to understand completely about PIVOT and refer to the second link and check if any provided method can help you achieve the requirement:
https://www.appsloveworld.com/sql-server-simple-way-to-transpose-rows-into-columns/
Efficiently convert rows to columns in sql server

Is it possible to retrieve only the timestamp from a influxDb query

Is it possible to pass the timestamp retuned in influxDb query to another query.
Select max("value")
from "temp" where ("floor" = "1);
Output
time max
---- ---
2020-01-17T00:00:00Z 573.44
Is it possible to pass the time from the result to another query?
You cannot do this with InfluxQL,it is not possible to nest the queries in a way that could pass the time range of the inner query to the outer query. it's another matter if you were using Flux (new Query Language but still in BETA).
In Flux this is possible, because you can access time as a column, which you can then use to query your other measurements as required. You can also use JOIN to do more advanced operations like cross measurement calculations etc.

What is the equivalent of a UNION statement

I need to chart physical measurements using Influx. All measurements are stored as series inside a single Influx "measurement".
Some are "current" values like temperatures, other are things like energy meter readings.
The problem is that these need different queries in order to produce visually attractive output. Charting the meter readings as current power is possible using the DIFFERENCE function.
SELECT difference(max("value")) AS "diff_value"
FROM "volkszaehler"."autogen"."data"
WHERE time > :dashboardTime:
GROUP BY time(1d), "title" FILL(linear)
For other values like temperatures the selection should be mean("value") without the difference.
Is there a way to "union" result sets in InfluxDB similar to mysql in order to display them in a single chart in Chronograf?
Sorry, this isn't possible and new functionality isn't being added to InfluxQL while Flux is being actively worked on.
https://github.com/influxdata/flux

influxdb query group by value

I am new to influxdb and the TICK environment so maybe it is a basic question but I have not found how to do this. I have installed Influxdb 1.7.2, with Telegraph listening to a MQTT server that receives JSON data generated by different devices. I have Chronograph to visualize the data that is being recieved.
JSON data is a very simple message indicating the generating device as a string and some numeric values detected. I have created some graphs indicating the number of messages recieved in 5 minutes lapse by one of the devices.
SELECT count("devid") AS "Device" FROM "telegraf"."autogen"."mqtt_consumer" WHERE time > :dashboardTime: AND "devid"='D9BB' GROUP BY time(5m) FILL(null)
As you can see, in this query I am setting the device id by hand. I can set this query alone in a graph or combine multiple similar queries for different devices, but I am limited to previously identifying the devices to be controlled.
Is it posible to obtain the results grouped by the values contained in devid? In SQL this would mean including something like GROUP BY "devid", but I have not been able to make it work.
Any ideas?
You can use "GROUP BY devid" if devid is a tag in measurement scheme. In case of devid being the only tag the number of unique values of devid tag is the number of time series in "telegraf"."autogen"."mqtt_consumer" measurement. Typically it is not necessary to use some value both as tag and field. You can think of a set of tags in a measurement as a compound unique index(key) in conventional SQL database.

Can an array be the value for an influxdb entry?

I am trying to write an influxdb query such that a measurement looks like
dummydata value=1,2,3,4
and influxdb doesn't like this format. I'm guessing influxdb cannot do this, but I can't find any documentation that says it cannot, nor do I see a feasible workaround. I have to write 500 points per timestamp: it seems to me that 500 separate measurements per timestamp would get hairy quick.
So:
Can influxdb accept an array/list as a value
If not, is there a workaround
Or is influxdb just the wrong tool for this job?
Thanks in advance.
InfluxDB accepts strings, float64s, int64s, and booleans as field values.
it seems to me that 500 separate measurements per timestamp would get hairy quick.
That's where you are mistaken. InfluxDB 0.10+ is specifically designed to encourage multiple fields per point, where a field is a measured value. What you want to write is a point like this:
dummydata value=1,value2=2,value3=3,value4=4...

Resources