influxdb - InfluxDB如何转义方括号“[”
问题描述
我正在查询流入数据库,如下所示,
select * from measurement where '/cda/stats/@name' =~ /cda\/stats.*/ limit 5;
上面的查询工作正常,但是当我尝试在查询字符串中指定方括号时它不起作用,例如"/cda/stats/[name='set']
select * from mgmgrand where '/cda/stats/@name' =~ /cda\/stats[name='set'].*/ limit 5;
不确定如何在上述查询中转义方括号。
反斜杠“\”不适用于方括号。
解决方案
我在 influx DB 中对此进行了测试,发现了一个奇怪的解决方案(我不知道它为什么会起作用)。如果您的标识符未加引号,将单引号更改为双引号,则替换'/cda/stats/@name'
为"/cda/stats/@name"
似乎可以解决此问题。
select * from mgmgrand where "/cda/stats/@name" =~ /\[/
//matches the value /cda/stats/[name='set']
在不更改引号的情况下,它适用于没有 [ 的值,但在尝试匹配 [ 字符时不起作用。
select * from mgmgrand where '/cda/stats/@name' =~ /cda/
//matches the value /cda/stats/[name='set']
select * from val1 where '/cda/stats/@name' =~ /\[/
//does not give an output
如果您使用带引号的标识符替换'/cda/stats/@name'
或"'/cda/stats/@name'"
修复"\"/cda/stats/@name\""
它。
推荐阅读
- java - 如何在Java中创建几个整数和输入整数的“最佳拟合”比较?
- mysql - 根据日期选择最后插入的行
- java - Java如何从浏览器/系统自动请求用户PKI证书?
- google-cloud-platform - 如何禁用 gke 主机的自动升级(不仅仅是节点池)
- r - 在 R 中通过 ID 随机分配已建立的值
- ruby-on-rails - 没有路线匹配 [POST] "/webhooks/orders/fulfilled" Shopify rails
- c++ - 合并排序 C++ 错误排序
- python - 在 python 脚本中有一个 wget 命令(Windows)
- python - 如何绘制时间序列的倒数
- python - 如何比 iterrows() 更有效地根据条件从 df 中删除行?(Python)