InfluxDB query using regular expression is not working - influxdb

I am using InfluxDB and have below mention data in measurement against field "jkey"
/interfaces/interface[name='xe-1/0/4']/state/counters/out-queue[queue-number='0']/allocated-buffer-size
/interfaces/interface[name='xe-1/0/5']/state/counters/out-queue[queue-number='0']/allocated-buffer-size
/interfaces/interface[name='xe-1/0/4']/state/counters/out-queue[queue-number='0']/allocated-buffer-size
I am using below mention query which is working fine with above data.
select * from "measurement" where jkey =~ /interfaces\/interface.*/;
Now, i want to select only those records that have value 'xe-1/0/5' in it.
Below Query is also working fine as long as "[" is not part of query.
select * from "measurement" where jkey =~ /name='xe-1\/0\/5']\/state\/counters\/in-pkts.*/ ;
Wondering what i am missing to escape in below mention query?
select * from "measurement" where jkey =~ /interfaces\/interface[name='xe-1\/0\/5']\/state\/counters\/in-pkts.*/;

Escaping this way fix the issue:
select * from "measurement" where jkey =~ /interfaces\/interface\[name='xe-1\/0\/5']\/state\/counters\/in-pkts.*/;

Related

is there are any alpha logic define in informix DB

i am using informix DB , i need to get records that contain alpha [A-Za-z] character on last character
what i try is :
select * from table_name
where (SUBSTR(trim(customer),-1,1)!='0' and SUBSTR(trim(customer),-1,1)!='1' and SUBSTR(trim(customer),-1,1)!='2' and SUBSTR(trim(customer),-1,1)!='3' and SUBSTR(trim(customer),-1,1)!='4' and SUBSTR(trim(customer),-1,1)!='5' and SUBSTR(trim(customer),-1,1)!='6' and SUBSTR(trim(customer),-1,1)!='7' and SUBSTR(trim(customer),-1,1)!='8' and SUBSTR(trim(customer),-1,1)!='9') or (SUBSTR(trim(customer),-1,1)=' ') or (SUBSTR(trim(customer),-1,1)='') or (customer IS NULL)
is there are any way to write where SUBSTR(trim(customer),-1,1)=alpha rather than write
SUBSTR(trim(customer),-1,1)!='0' and SUBSTR(trim(customer),-1,1)!='1' and SUBSTR(trim(customer),-1,1)!='2' and SUBSTR(trim(customer),-1,1)!='3' and SUBSTR(trim(customer),-1,1)!='4' and SUBSTR(trim(customer),-1,1)!='5' and SUBSTR(trim(customer),-1,1)!='6' and SUBSTR(trim(customer),-1,1)!='7' and SUBSTR(trim(customer),-1,1)!='8' and SUBSTR(trim(customer),-1,1)!='9'
If you have a 'recent' version of Informix (anything over 12.10 should do) you can use regex_match():
https://www.ibm.com/support/knowledgecenter/SSGU8G_14.1.0/com.ibm.dbext.doc/ids_dbxt_544.htm
Something like :
> select * from table(set{'test','test1','tesT'})
where regex_match(unnamed_col_1, '[a-zA-Z]$');
unnamed_col_1
test
tesT
2 row(s) retrieved.
>
You can use the Informix MATCHES operator, that is supported in any version.
The query would be like this:
select * from table_name
where customer matches "*[A-Za-z]"

InfluxDB - Including multiple values in where clause based on tags

I'm trying to query data based on tag values. Is it possible to include multiple queries in the where clause . I could not find an operator similar to the IN operator in SQL.
select * from students where rollNumber='1' limit 10
students is the measurement and rollNumber is a tag. I want include multiple values of rollNumber in the query.
Any suggestions to solve the problem?
InfluxDB does not have IN operator, however it supports Go-lang regular expressions in WHERE clause for fields and tags. Regular expressions are enclosed with / and require adding ~ after comparison operator:
select * from students where rollNumber =~ /1|2|3/ limit 10
This will return 10 students, where rollNumber tag contains 1 or 2 or 3.
For a precise match the following should work:
select * from students where rollNumber =~ /^[1|2|3]$/ limit 10
Note: In case of filtering fields, if the type of fields is not string, regex will not work...
But as noted in the comments, using OR operator with explicit comparison should work better, as tag index can be used for more efficient querying.

FTS5 cannot use Operators with Match operator

I'm doing full text search using sqlite and below are some select query examples that I'm using.
Ex:
SELECT * FROM table WHERE table MATCH 'column:father* OR for*' ORDER BY rank;
SELECT * FROM table WHERE table MATCH 'column:exam* AND yo*' ORDER BY rank;
These queries are not working properly. Giving me all the rows in the database as the result. I cannot use AND/OR with the Match operator when using asterisk. Any solutions?
Thanks.

concatenate values from two columns and compare it against one value in sqlite

I am using sqlite in one my ios project where among other columns there are two columns. one has country code for mobile dialing like +880 and other column has rest of the mobile number like 1912353697. Now i want to join values from these two columns and compare the result value against like +8801912353697 and if matches pull the corresponding name value in that table . what would be the right query. I have tried like SELECT name FROM CONTACT_LIST WHERE (SELECT mblDc || mbl FROM CONTACT_LIST) = "+8801617634317" ; but that does not work .
A help would be appreciated.
Try:
SELECT name FROM CONTACT_LIST
WHERE mblDc || mbl = "+8801617634317";
From SQLite documentation: The || operator is "concatenate" - it joins together the two strings of its operands.
please check
How to concatenate strings with padding in sqlite
using substr function we can do the job and the query should be like
SELECT name FROM CONTACT_LIST WHERE (mblDc || mbl) = "+8801617634317" ;

RuntimeError: ERROR Mrelation "tablename" does not exist

Rails - 2.3.8
Database - Postgres(9.2)
Active record query is not able to generate tablename in double quotes ie
# this ran fine
Table.find_by_sql('Select * from "Table" Limit 1')
Sql generated - Select * from "Table" Limit 1
But issue comes in,
Table.find(:first)
Sql generated - Select * from Table Limit 1 (Clearly noticed that table not in double quotes)
Active record displaying error
ActiveRecord::StatementInvalid: RuntimeError: ERROR
C42P01 Mrelation "Table" does not exist
P15 Fparse_relation.c L864
RparserOpenTable: SELECT * FROM Table LIMIT 1
I feel that postgresql adapter is not able to generate tablename in double quotes.
I never get a chance to work on Postgres. But I have a workaround solution for this. Try as follows:
table_name = '"Table"'
table_name.find(:first)
I haven't try this in my machine since I do not have the required setup. I hope it should work.

Resources