I'm having trouble understanding how to add tags to data series as I do SELECT INTO
queries. I have an Influxdb of the NYTimes COVID dataset where I've used the cases
and deaths
fields as fields
and the state
and county
information as tags.
I can aggregate data from neighboring counties in a query like this:
SELECT sum("cases") AS "cases" FROM "ny_covid"."autogen"."value" WHERE ("state"='Pennsylvania') AND ("county"='Philadelphia' OR "county"='Delaware') GROUP BY time(1d) FILL(null)
This works perfectly. But I want to save this aggregated data into a new database for doing other queries. Which I can do like this:
SELECT sum("cases") AS "cases" INTO "new_covid"."autogen"."value" FROM "ny_covid"."autogen"."value" WHERE ("state"='Pennsylvania') AND ("county"='Philadelphia' OR "county"='Delaware') GROUP BY time(1d) FILL(null)
My question is, how do I add a tag like location=Philly
to the data I've just inserted into the new_covid
database? Because, I'd like to do a few other location level aggregations and it seems like the tag
is the way to keep these values distinct.
SELECT sum("cases") AS "cases" INTO "new_covid"."autogen"."value" FROM "ny_covid"."autogen"."value" WHERE ("state"='Pennsylvania') AND ("county"='Dauphin' OR "county"='Lancaster') GROUP BY time(1d) FILL(null)
All of the searching I've done has just been about using the tags in queries or preserving them when copying across databases. But I haven't been able to find anything about attaching tags in SELECT INTO
type statements.
state,county
? – Jan Garajsum
of 6 counties as a new area in the new database. That way I can pull them out of thenew_covid
database by tag and distinguish it from the 7 countysum
around Pittsburg or 8 around Harrisburg. I also don't know how I would transfer the tags from the previous DB into the new one anyway. This is also a general question: "How do you add tags to data inserted with aSELECT INTO
statement"? – JudoWillselect data; add new tag to data; insert data;
. Use your favorite language with InfluxDB support (e.g. python) and code it. – Jan GarajSELECT INTO
statements? The only way to add tags is to pull data out of one database and then re-insert it again. Conversely, the only way to distinguish aggregations inSELECT INTO
statements is to send them to distinctfields
? – JudoWill