0
votes

I am using below Go client ("github.com/influxdata/influxdb/client/v2") to query InfluDB and it is working fine

q = fmt.Sprintf("SELECT * FROM %s WHERE time > now() - 3600s", Measurement)

but I want to use Go time variable instead of InfluxDB now()

t := time.Now().Format(time.RFC3339)
q = fmt.Sprintf("SELECT * FROM %s WHERE time > %s - 3600s", Measurement, t)

but getting error parsing query: found -01, expected ; at line 1, char 101

1
You might want to calculate t - 3600s in Go and use that value in your query. Date/time in InfluxDB has its own format, surrounded by single quotes. See: stackoverflow.com/questions/38299252/query-influxdb-for-a-dateGVdP

1 Answers

1
votes

Date strings must be single quoted. Using

t := time.Now().Format(time.RFC3339)
q = fmt.Sprintf("SELECT * FROM %s WHERE time > '%s' - 3600s", Measurement, t)

Should solve your issue.