14

I am using influxDB instead of MySQL for time series analysis. In my database data, I have a series which is called /HFT/Data_HFT/OrderBook/DCIX_OB. That name is irrelevant and it was created by error. That series has 89 million lines, so it would be very long to recreate that series.

So this is not a solution for me:

SELECT * INTO new_name FROM old_name
DROP MEASUREMENT old_name

I tried that solution, but it didn't work at all. Here is the error :

> RENAME MEASUREMENTS 'OLD_NAME' to 'NEW_NAME'
ERR: error parsing query: found RENAME, expected SELECT, DELETE, SHOW, CREATE, DROP, EXPLAIN, GRANT, REVOKE, ALTER, SET, KILL at line 1, char 1

How could I rename it?

4
  • AFAIK, InfluxDB still doesn't support series rename. Commented May 14, 2018 at 13:22
  • That solution is also wrong. Commented Jul 15, 2019 at 1:51
  • This solution works SELECT * INTO new_name FROM old_name do copy and paste the old name(to avoid case mismatch) where it is showing time and written status. Commented Dec 13, 2019 at 7:15
  • 1
    WARNING: The solution SELECT * INTO new_name FROM old_name will convert all your tags into fields of type string and your data will be corrupt. There is no current way to rename. To do the copy properly, see my solution below.
    – Sarang
    Commented Mar 6, 2020 at 12:18

2 Answers 2

12

There is no official way to rename a measurement yet. The way to do it is:

  1. Find all tags in your measurement using SHOW TAG KEYS FROM MyMeasurement. Let's assume your tags were tag1 and tag2
  2. Copy all data into a new measurement using SELECT * INTO MyMeasurementCopy from MyMeasurement GROUP BY tag1,tag2
  3. Once you are 100% sure all data is copied, you can drop the old data using DROP MEASUREMENT MyMeasurement

It's a long process but it works.

3
  • 13
    You can use SELECT * INTO MyMeasurementCopy from MyMeasurement GROUP BY * to avoid the manual process of finding all the tags. See this answer: stackoverflow.com/a/37084262/1658010
    – Gediminas
    Commented Apr 6, 2020 at 8:54
  • 1
    That would be awesome if it works! I hope it does not convert all fields into tags. If anyone has tried this, would be great to know.
    – Sarang
    Commented Apr 7, 2020 at 15:33
  • 3
    I can confirm it works. Tested in influx version 1.7.9.
    – wizzfizz94
    Commented May 7, 2020 at 5:19
2

Adapted from @Sarang's answer and comments.

There is no RENAME operation but you can copy a measurement into another, then delete it.

SELECT * INTO DestMeasurementCopy from SrcMeasurement GROUP BY *
DROP MEASUREMENT SrcMeasurement

GROUP BY * ensures the tags are preserved. See this answer and comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.