Skip to content

一、删除

  • delete 语句
 DELETE FROM <measurement_name> WHERE [<tag_key>='<tag_value>'] | [<time interval>]
 DELETE FROM <measurement_name> WHERE [<tag_key>='<tag_value>'] | [<time interval>]

==只允许根据tag和时间来进行删除操作==

1.1 根据时间删除

> select * from userInfo
name: userInfo
time                blog   name userId
----                ----   ---- ------
1568468825672884073 ksksks blog 10
1568468830240881233 ksksks blog 1
1568468833161251273 ksksks blog 2

> delete from userInfo where time=1568468825672884073

> select * from userInfo
name: userInfo
time                blog   name userId
----                ----   ---- ------
1568468830240881233 ksksks blog 1
1568468833161251273 ksksks blog 2
> select * from userInfo
name: userInfo
time                blog   name userId
----                ----   ---- ------
1568468825672884073 ksksks blog 10
1568468830240881233 ksksks blog 1
1568468833161251273 ksksks blog 2

> delete from userInfo where time=1568468825672884073

> select * from userInfo
name: userInfo
time                blog   name userId
----                ----   ---- ------
1568468830240881233 ksksks blog 1
1568468833161251273 ksksks blog 2

1.2 根据tag删除

  • 注意name为保留名,因此需要用双引号括起来
> show tag keys from userInfo
name: userInfo
tagKey
------
name

> select * from userInfo
name: userInfo
time                blog   name userId
----                ----   ---- ------
1568468830240881233 ksksks blog 1
1568468833161251273 ksksks blog 2

> delete from userInfo where "name"='blog'

> select * from userInfo
>
> show tag keys from userInfo
name: userInfo
tagKey
------
name

> select * from userInfo
name: userInfo
time                blog   name userId
----                ----   ---- ------
1568468830240881233 ksksks blog 1
1568468833161251273 ksksks blog 2

> delete from userInfo where "name"='blog'

> select * from userInfo
>

1.3 不同保存策略的数据删除

> insert add_test,name=YiHui,phone=110 boy=true,age=19i,user_id=2

> insert into "1D" add_test,name=YiHui,phone=110 boy=true,age=19i,user_id=1

> insert into "1Y" add_test,name=YiHui,phone=110 boy=true,age=19i,user_id=1

>  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
1568601987939395085 19  true              YiHui 110   2

> select * from "1Y".add_tes

> 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
1568602026240146951 19  true              YiHui  110   1

> delete from add_test where "name"='YiHui'

> select * from add_test

> 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
>
> insert add_test,name=YiHui,phone=110 boy=true,age=19i,user_id=2

> insert into "1D" add_test,name=YiHui,phone=110 boy=true,age=19i,user_id=1

> insert into "1Y" add_test,name=YiHui,phone=110 boy=true,age=19i,user_id=1

>  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
1568601987939395085 19  true              YiHui 110   2

> select * from "1Y".add_tes

> 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
1568602026240146951 19  true              YiHui  110   1

> delete from add_test where "name"='YiHui'

> select * from add_test

> 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
>

根据tag进行删除时,默认策略,和”1D”保存策略中的数据都被删除掉