How to copy data between measurements

I’m currently running OSS 2.0, which has migrated data from 1.x
Sometimes I need to move data between measurements, which was relatively easy in InfluxQL, but unfortunately the support is read-only, so SELECT INTO is not an option anymore.
Is there a way to merge measurement data using Flux?

You could use union or join function to merge two input streams into a single output stream.

1 Like

Thanks for the links, the union part is clear, so I can query and merge the measurements I need.
To be more specific, by merge, I also mean to store the result not only union/join them on the fly :slight_smile:
So the harder part for me is the InfluxQL INTO clause equivalent of Flux, which I couldn’t find in the docs.

Question in short: Can I use Flux to insert/store/write query results back into InfluxDB?

@kajarit Yes, you can. Query then data, update the measurement name, then write it back to InfluxDB with to(). Queries in 2.x must be scoped by time, so you have to provide a time range. Depending on how much data is in the measurement, you may need to do this in time-based batches:

from(bucket: "example-bucket")
    |> range(start: 2021-11-21T00:00:00Z, stop: 2021-11-22T00:00:00Z)
    |> filter(fn: (r) => r._measurement == "old")
    |> set(key: "_measurement", value: "new")
    |> to(bucket: "example-bucket")
1 Like