0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

InfluxDBv2 CLIでSQLのDELETEあるいはTRUNCATE相当の事をする場合

Posted at

macOSでの小さなハマりごと。date -uオプションを使いましょう。

公式ドキュメント

influx deleteコマンドでできる。

今現在のドキュメントには次のコマンドラインで例示がされている。

influx delete --bucket example-bucket \
  --start '1970-01-01T00:00:00Z' \
  --stop $(date --utc +"%Y-%m-%dT%H:%M:%SZ") \
  --predicate '_measurement="example-measurement" AND exampleTag="exampleTagValue"'

macOSでの問題点

しかし上記のコマンドの3行目までをmacOSでコピペし、条件を変えてもその手前で動かない。

問題点は単純にdateコマンドオプションが異なり-—utcを使っているから。

GNUとBSDのdateコマンドの相違については次の記事を参照

それぞれのman dateを見てみると。

GNU date (Debian)

       -u, --utc, --universal
              print or set Coordinated Universal Time (UTC)

BSD date (macOS)

     -u      Display or set the date in UTC (Coordinated Universal) time.  By default date displays the time in the time zone described by /etc/localtime or the TZ environment variable.

BSDでは-uのみGNUでは-u-—utc-—universalも受け付ける。

ということで

どっちもOKなdate -uが良い。

条件なしで全件削除の場合は

$ influx delete --bucket example-bucket \        
  --start '1970-01-01T00:00:00Z' \
  --stop $(date -u +"%Y-%m-%dT%H:%M:%SZ") 

InfluxDataのドキュメントのCLIインストール説明ではmacOSが最初に書かれているのに…

-uで例示してくれれば、macOSでもLinuxでも両方コピペで動くのにねぇ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?