7

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.

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

Comments

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") 

Comments

1

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/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.