【问题标题】:InfluxDB how to escape square brackets "["InfluxDB如何转义方括号“[”
【发布时间】:2019-08-16 07:19:58
【问题描述】:

我正在查询涌入 D.B.如下图,

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;

不确定如何在上述查询中转义方括号。

反斜杠“\”不适用于方括号。

【问题讨论】:

  • 反斜杠应该起作用。根据“不工作”的含义,我认为问题的根源可能是“stats”和“[name='set]'”之间缺少/。所以你最终会得到类似/cda\/stats\/\[name='set'\]
  • 它不工作。我还需要转义单引号 ' 吗?
  • 否 - 正则表达式似乎在修复该斜线后工作,至少如果我正确理解您正在测试的内容。您可以根据您的值之一测试您的表达式here
  • 我正在尝试读取这些数据:select * from mgmgrand where '/cda-stats/server-api-agg/server-api-server/server-api-stats/@name' =~ /cda-stats\/server-api-agg\/server-api-server\/server-api-stats\/[name='ExprCntrFarmRead'].*/ 限制 5;但它没有回升,在数据库中的值为 /cda-stats/server-api-agg/server-api-server/server-api-stats[name='ExprCntrFarmRead']

标签: influxdb influxql


【解决方案1】:

我在 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\"" 会修复它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    相关资源
    最近更新 更多