5

I'm using influxdb 2.0 to store stock history data. I use ticker as tag name and AAPL(GOOG.. etc..) as tag value to store stock history candle data.

Now, I want to get a tag all values by flux language in my program. In other words, get all values of tag ticker for getting all stock symbols.

But I don't know how to do this. I have search google but all answer that I found is talking about influxdb 1.x not the 2.0.

huang
  • 919
  • 11
  • 22

3 Answers3

7

Maybe can try this: InfluxDB Docs.

The code in Function definition works for me.

I added

|> group(columns: ["tag_name"])
|> distinct(column: "tag_name")
|> keep(columns: ["_value"])

after my filter, and then I got all the tag values.

welinn
  • 71
  • 2
2

Please see below code which will return all values of tag ticker :

from(bucket: "<Your bucket name>")
// Give range of start and stop as per your usecase
|> range (start: 2015-08-01T00:00:00Z, stop: 2021-06-01T00:00:00Z)
|> filter(fn:(r) => r._measurement == "<Your Measurement Name>")
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> group()
|> distinct(column: "ticker")
Altaf
  • 2,838
  • 1
  • 16
  • 8
0

Don't do any custom queries they are very inperformant when the timeframe becomes big enough.

Here is the idiomatic way:

import "influxdata/influxdb/schema"

schema.tagValues(bucket: "roads", tag: "component_name", start: v.timeRangeStart, stop: v.timeRangeStop)

Source: https://docs.influxdata.com/flux/v0.x/stdlib/influxdata/influxdb/schema/tagvalues/

Valerij Dobler
  • 1,848
  • 15
  • 25