Reputation: 6855
I would like to use InfluxDB to store forecast data. Each forecast has an emission date, a target date, and a value. I receive several forecasts with different emission dates for the same target date.
I would like to be able to retrieve
Upvotes: 0
Views: 240
Reputation: 19228
Essentially you will be looking at having your forecast's emission_dates
to be stored as part of the time
field, then the target_dates
as a tag and lastly storing your value
in the value field.
Example:
name: forecast
time target_dates value
---- ------------ -----
1546516616386036270 1546000000000000000 500
1546516616390715128 1547000000000000000 600
1546516616734277026 1548000000000000000 700
The reason why I choice target_dates
as tag is because tags are indexed. In case you are not aware of indexing you can find out more here.
See under "Why indexing matters: The schema case study"
This scheme design meets your requirement because;
To get the latest forecast based on the emission date, you can do a SELECT * from forecast order by DESC limit 1
To get all forecast of a certain emission date. Simply do SELECT * FROM "forecast" WHERE "target_dates" = '1547000000000000000'
Something worth noting here is that the target_dates
above is on epoch
time, format, you should be able to store any string datetime format you want.
Upvotes: 1