Skip to content

一、Insert 使用说明

https://docs.influxdata.com/influxdb/v1.7/tools/shell/#write-data-to-influxdb-with-insert

https://docs.influxdata.com/influxdb/v1.7/query_language/database_management/#delete-series-with-delete

1.1 基本语法

bash
insert into <retention policy> measurement,tagKey=tagValue fieldKey=fieldValue timestamp
insert into <retention policy> measurement,tagKey=tagValue fieldKey=fieldValue timestamp
  • 插入的语句写法
insert + measurement + "," + tag=value,tag=value + + field=value,field=value

tag与tag之间用逗号分隔;field与field之间用逗号分隔

tag与field之间用空格分隔

tag都是string类型,不需要引号将value包裹

field如果是string类型,需要加引号
insert + measurement + "," + tag=value,tag=value + + field=value,field=value

tag与tag之间用逗号分隔;field与field之间用逗号分隔

tag与field之间用空格分隔

tag都是string类型,不需要引号将value包裹

field如果是string类型,需要加引号

1.2 四种类型

  • field有四种类型,int, float, string, boolean
类型方式示例
float数字user_id=21
int数字iage=18i
booleantrue/falseboy=true
String"" or ''email="sfds@126.com"
  • instert
> insert add_test,name=YiHui,phone=110 user_id=20,email="test@126.com"

>  select * from add_test
name: add_test
time                email        name  phone user_id
----                -----        ----  ----- -------
1568470304939913644 test@126.com YiHui 110   20

#查看
> select * from add_test
name: add_test
time                age boy  email        name  phone user_id
----                --- ---  -----        ----  ----- -------
1568470304939913644          test@126.com YiHui 110   20
> insert add_test,name=YiHui,phone=110 user_id=20,email="test@126.com"

>  select * from add_test
name: add_test
time                email        name  phone user_id
----                -----        ----  ----- -------
1568470304939913644 test@126.com YiHui 110   20

#查看
> select * from add_test
name: add_test
time                age boy  email        name  phone user_id
----                --- ---  -----        ----  ----- -------
1568470304939913644          test@126.com YiHui 110   20
  • field类型
> insert add_test,name=YiHui,phone=110 user_id=21,email="test@126.com",age=18i,boy=true

> select * from add_test
name: add_test
time                age boy  email        name  phone user_id
----                --- ---  -----        ----  ----- -------
1568470399995857565 18  true test@126.com YiHui 110   21
> insert add_test,name=YiHui,phone=110 user_id=21,email="test@126.com",age=18i,boy=true

> select * from add_test
name: add_test
time                age boy  email        name  phone user_id
----                --- ---  -----        ----  ----- -------
1568470399995857565 18  true test@126.com YiHui 110   21

1.3 tag

> show tag keys from add_test;
name: add_test
tagKey
------
name
phone
> show tag keys from add_test;
name: add_test
tagKey
------
name
phone

1.4 field

> show field keys from add_test;
name: add_test
fieldKey fieldType
-------- ---------
age      integer
boy      boolean
email    string
user_id  float
> show field keys from add_test;
name: add_test
fieldKey fieldType
-------- ---------
age      integer
boy      boolean
email    string
user_id  float

1.5 时间戳指定

注意时间为ns

> insert add_test,name=YiHui,phone=110 user_id=22,email="test@126.com",age=18i,boy=true 1564150279123000000

> select * from add_test
name: add_test
time                age boy  email        name  phone user_id
----                --- ---  -----        ----  ----- -------
1564150279123000000 18  true test@126.com YiHui 110   22
注意时间为ns

> insert add_test,name=YiHui,phone=110 user_id=22,email="test@126.com",age=18i,boy=true 1564150279123000000

> select * from add_test
name: add_test
time                age boy  email        name  phone user_id
----                --- ---  -----        ----  ----- -------
1564150279123000000 18  true test@126.com YiHui 110   22

1.6 指定保存策略插入数据

  • 写入数据时,如果需要指定保存策略
#查看下
>  show retention policies on test
name    duration  shardGroupDuration replicaN default
----    --------  ------------------ -------- -------
autogen 0s        168h0m0s           1        true
1Y      8784h0m0s 168h0m0s           1        false

> insert into "1Y" add_test,name=YiHui2,phone=911 user_id=23,email="test@126.com",age=18i,boy=true 1564150279123000000
> select * from add_test;
name: add_test
time                age boy  email        name  phone user_id
----                --- ---  -----        ----  ----- -------
1564150279123000000 18  true test@126.com YiHui 110   22
1568470304939913644          test@126.com YiHui 110   20
1568470399995857565 18  true test@126.com YiHui 110   21

> select * from "1Y".add_test;
name: add_test
time                age boy  email        name   phone user_id
----                --- ---  -----        ----   ----- -------
1564150279123000000 18  true test@126.com YiHui2 911   23
#查看下
>  show retention policies on test
name    duration  shardGroupDuration replicaN default
----    --------  ------------------ -------- -------
autogen 0s        168h0m0s           1        true
1Y      8784h0m0s 168h0m0s           1        false

> insert into "1Y" add_test,name=YiHui2,phone=911 user_id=23,email="test@126.com",age=18i,boy=true 1564150279123000000
> select * from add_test;
name: add_test
time                age boy  email        name  phone user_id
----                --- ---  -----        ----  ----- -------
1564150279123000000 18  true test@126.com YiHui 110   22
1568470304939913644          test@126.com YiHui 110   20
1568470399995857565 18  true test@126.com YiHui 110   21

> select * from "1Y".add_test;
name: add_test
time                age boy  email        name   phone user_id
----                --- ---  -----        ----   ----- -------
1564150279123000000 18  true test@126.com YiHui2 911   23