3

I am querying influx D.B. as shown below,

select * from measurement where '/cda/stats/@name' =~ /cda\/stats.*/ limit 5;

Above query is working fine, but when i try to specify square brackets in the query string it is not working, for e.g. "/cda/stats/[name='set']

select * from mgmgrand where '/cda/stats/@name' =~ /cda\/stats[name='set'].*/ limit 5;

Not sure how to escape square brackets in the above query.

Back slash "\" is not working with square brackets.

loic.lopez
  • 2,013
  • 2
  • 21
  • 42
Ammad
  • 4,031
  • 12
  • 39
  • 62
  • 1
    Backslashes _should_ work. Depending on what "not working" means, I think the root of the problem might be a missing `/` between "stats" and "[name='set]'". So you'd end up with something like `/cda\/stats\/\[name='set'\]` – Sculper Apr 10 '19 at 20:10
  • It's not working. Do i need to escape the single quotes ' as well? – Ammad Apr 11 '19 at 22:46
  • No - the regex seems to work after fixing that slash, at least if I'm correctly understanding what you're testing against. You can test your expression against one of your values [here](https://regex-golang.appspot.com/assets/html/index.html). – Sculper Apr 11 '19 at 23:43
  • I am trying to read this data: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'\].*/ limit 5; But it is not picking up and in DB value is /cda-stats/server-api-agg/server-api-server/server-api-stats[name='ExprCntrFarmRead'\] – Ammad Apr 12 '19 at 00:51

1 Answers1

1

I tested this in influx DB and found a weird solution (I don't know why it works). If your identifer is unquoted changing single quotes to double quotes, replacing '/cda/stats/@name' with "/cda/stats/@name" seems to fix it.

select * from mgmgrand where "/cda/stats/@name" =~ /\[/
//matches the value /cda/stats/[name='set']

Without changing the quotes it works fine for value without [ , but doesnt work when trying to match a [ character.

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

If you use a quoted identifier replacing '/cda/stats/@name' with "'/cda/stats/@name'" or "\"/cda/stats/@name\"" fixes it.

Sandeep Polamuri
  • 609
  • 4
  • 10