Regex not supported in sql command with "contains" clause - mysql

I am not a seasonal Windows user, I got a task wherein I had to query the Window Index search table i.e "Systemindex" for fetching some user specific data from the db.
And for this I have to match a pattern basically a regular expression while fetching the data.
SELECT System.FileName, System.ItemPathDisplay, System.DateCreated, System.DateModified, System.ItemName, System.KindText FROM Systemindex WHERE Contains('“(?=^[A-Za-z\d!##\$%\^&\*\(\)_\+=]{9,32}$)”');
The above would allow us to search for say stored passwords.
But when I query the db using the below command I was getting an error. And later I came to know that the "contains" clause
does not support regular expression. Is there an alternative to achieve this?

there is REGEXP operator http://dev.mysql.com/doc/refman/5.7/en/regexp.html,
use smth like this
SELECT * FROM Systemindex WHERE some_column REGEXP 'your_regex'

Related

MS Access query with pattern

I am trying to implement in MS Access following query filter. I am trying do not show the numbers from my table which contains following pattern:
"NNNNNN_NNNN_NNN" AND "NNNNNN_NNNN_NNN-S/Z"
If I have in my database a number "123456_123_123" or "12345_1234_12" I cannot see them. So my filter pattern doesn't work correctly. Is there possibility to work in Access Query with underline symbols? How can I create correct pattern?
Thank you for any tip!
Use the operator LIKE:
SELECT *
FROM tablename
WHERE ([columnname] NOT LIKE '######_####_###')
AND ([columnname] NOT LIKE '######_####_###-S/Z')
The wildcard '#' represents a single digit.

Attempting find an embedded string in database with mysql

I'm attempting to query our database to find specific types of transactions with unique parameters.
There are multiple formats and I'm looking to get the transactions with the -Q/ parameter.
BCR*DEVSTS
BCR*1150
BCR*1150/28AUG
BCR*DEVSTS-Q/28AUG
BCR*DEV-Q/28AUG
I'm able to find the BCR transactions but due to memory constraints I can only get the first 10k rows and they don't have the -Q/ parameter. I'm trying to create a query that will only select the required transactions.
I used the following to query for the basis transaction:
select *
from transaction_200827
where reqresponse= 'Q' and message rlike '^BCR.*'
I've reviewed multiple websites but haven't been able to find an example of this scenario. I've tried variations on the examples provided and haven't been successful:
select * from transaction_200827 where reqresponse= 'Q' and message rlike '^BCR(Q/).*'
select * from transaction_200827 where reqresponse= 'Q' and message rlike '^BCR%Q/%.*'
I'm fairly new to building queries and would appreciate any guidance or direction for generating this type of query.
You're mixing regexp and LIKE patterns. Use either
message LIKE 'BCR%-Q/%'
or
message RLIKE '^BCR.*-Q/'
You're also missing the - before Q in your patterns.
There's no need to add .* to the end of the regexp -- RLIKE succeeds when the regexp matches anywhere in the string, it doesn't have to match the entire string (the ^ anchor forces it to match starting from the beginning, but there's no $ anchor extending it to the end).
If the column has an index, I recommend using LIKE -- in my experience, RLIKE doesn't take advantage of indexes. Either way, the index will only be used for matching the BCR at the beginning, the rest requires scanning all the values with that prefix.

MYSQL REGEXP with JSON array

I have an JSON string stored in the database and I need to SQL COUNT based on the WHERE condition that is in the JSON string. I need it to work on the MYSQL 5.5.
The only solution that I found and could work is to use the REGEXP function in the SQL query.
Here is my JSON string stored in the custom_data column:
{"language_display":["1","2","3"],"quantity":1500,"meta_display:":["1","2","3"]}
https://regex101.com/r/G8gfzj/1
I now need to create a SQL sentence:
SELECT COUNT(..) WHERE custom_data REGEXP '[HELP_HERE]'
The condition that I look for is that the language_display has to be either 1, 2 or 3... or whatever value I will define when I create the SQL sentence.
So far I came here with the REGEX expression, but it does not work:
(?:\"language_display\":\[(?:"1")\])
Where 1 is replaced with the value that I look for. I could in general look also for "1" (with quotes), but it will also be found in the meta_display array, that will have different values.
I am not good with REGEX! Any suggestions?
I used the following regex to get matches on your test string
\"language_display\":\[(:?\"[0-9]\"\,)*?\"3\"(:?\,\"[0-9]\")*?\]
https://regex101.com/ is a free online regex tester, it seems to work great. Start small and work big.
Sorry it doesn't work for you. It must be failing on the non greedy '*?' perhaps try without the '?'
Have a look at how to serialize this data, with an eye to serializing the language display fields.
How to store a list in a column of a database table
Even if you were to get your idea working it will be slow as fvck. Better off to process through each row once and generate something more easily searched via sql. Even a field containing the comma separated list would be better.

MySql extract data from a database based on two columns

I Am trying to create/run an my sql query in such a way that the sql selects data based a some conditions from Column 1 (USER) but at the same time Excludes some data, based on some conditions from column 2 (ADDRESS)
E.g.:
SELECT ADDRESS,USER
FROM Data1.Table1
WHERE FIELD(USER,'%AMIT%','%JOHN%','%SANDEEP%','%WARNE%')
AND ORIGINATING_ADDRESS NOT LIKE 'MUMBAI','CHINA','PAKISTAN'
This is giving error.Can some one please help ?
Use NOT IN to discard list of values from select. Considering that you want to discard when there is exact match
ORIGINATING_ADDRESS NOT IN ('MUMBAI','CHINA','PAKISTAN')
When you want to use pattern search and discard the use this
ORIGINATING_ADDRESS NOT LIKE '%MUMBAI%' OR
ORIGINATING_ADDRESS NOT LIKE '%CHINA%' OR
ORIGINATING_ADDRESS NOT LIKE '%PAKISTAN%'
For a set of values, use NOT IN, instead of NOT LIKE.
You might find regular expressions simpler for this purpose:
SELECT ADDRESS,USER
FROM Data1.Table1
WHERE USER REGEXP 'AMIT|JOHN|SANDEEP|WARNE' AND
ORIGINATING_ADDRESS NOT REGEXP 'MUMBAI|CHINA|PAKISTAN';

passing a variable to SQL statement in KNIME

Using KNIME, I would like to analyze data in a specific subset of columns in my database
but without using limiting SQL queries such as
Select *
From table
Where name like 'PAIN%'
Is there a way to do this in KNIME?
Try to find specific value within the column of choice by using:
Select distinct(column_name) from table;
You can pick from the expected result to filter your data
Select * from table column_name like 'result_one';
Assuming the column_name data type is in character.
To filer columns use the "Column Filter" node. You can filter the columns specifically, by RegEx on the column name or by column type (int, double, etc.) To filter rows based on content, use the "Row Filter" node, and select column to test and "filter based on collection elements" using pattern matching. This can also use RegEx. For mulitple columns use multiple nodes.
the knime did not support like for now, so I used the mysql locate or FIND_IN_SET function
SELECT id FROM address where LOCATE($street_Arr[0]$,street) > 0
SELECT id FROM address where FIND_IN_SET($street_Arr[0]$,street) > 0
however in the same situation u might be able to use knime joins much faster.