Regex based SQL queries sqlalchemy-hana - sqlalchemy

Are regex based SQL queries supported by sqlalchemy-hana?
what should be the appropriate syntax for executing this SQL query and getting back the resulting pandas dataframe
SELECT ATTRIBUTE_VALUE FROM PARSING2 WHERE (ATTRIBUTE_NAME NOT REGEXP "^ADDITIONAL")

The syntax - WHERE (ATTRIBUTE_NAME NOT REGEXP "^ADDITIONAL") is not supported by SAP HANA.
SAP HANA uses a SQL function named LIKE_REGEXPR for regular expression matching. For further details have a look at:
https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.00/en-US/b40d483dd34d47aa9cc89b4d8a6e617e.html

Related

MySQL Regular expression with alternation group not working

I'm trying to match this string "محمد مصلح حسن القطان" from a column in MySQL table using regular expression which have different alternations of the letter "ا". I have tried this
SELECT caseTitle FROM cases where caseTitle REGEXP 'قط([ا|أ|آ|إ])ن';
For some reason it doesn't work, when I try this
SELECT caseTitle FROM cases where caseTitle REGEXP 'قط([ا|أ|آ|إ])';
It works and matches the string, I'm using Google Cloud SQL with version 5.7 and unfortunately, I can't define custom collation for Arabic letters which should have solved my problem so I had to use regular expressions.

SQL Server soundex and MySQL soundex difference

Hello I want to use Soundex on SQL Server. I found good example for MySQL:
SELECT SOUNDEX('game of thrones')
When I tried this query:
MySQL returns : G513652
SQL Server returns : G500
I searched but couldn't find why. Aren't they same?
From the MySQL documentation:
A standard soundex string is four characters long, but the SOUNDEX() function returns an arbitrarily long string. You can use SUBSTRING() on the result to get a standard soundex string.
The version that MSSQL returns is the normal length, MySQL is just being different for some reason.
Also looks like MSSQL is only looking at the first word. With a third soundex implementation, SOUNDEX('game') gives G500 and SOUNDEX('game of thrones') gives G513.

Regex not supported in sql command with "contains" clause

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'

MySQL for replace with wildcard

I'm trying to write a SQL update to replace a specific xml node with a new string:
UPDATE table
SET Configuration = REPLACE(Configuration,
"<tag>%%ANY_VALUE%%</tag>"
"<tag>NEW_DATA</tag>");
So that
<root><tag>SDADAS</tag></root>
becomes
<root><tag>NEW_DATA</tag></root>
Is there a syntax im missing for this type of request?
Update: MySQL 8.0 has a function REGEX_REPLACE().
Below is my answer from 2014, which still applies to any version of MySQL before 8.0:
REPLACE() does not have any support for wildcards, patterns, regular expressions, etc. REPLACE() only replaces one constant string for another constant string.
You could try something complex, to pick out the leading part of the string and the trailing part of the string:
UPDATE table
SET Configuration = CONCAT(
SUBSTR(Configuration, 1, LOCATE('<tag>', Configuration)+4),
NEW_DATA,
SUBSTR(Configuration, LOCATE('</tag>', Configuration)
)
But this doesn't work for cases when you have multiple occurrences of <tag>.
You may have to fetch the row back into an application, perform string replacement using your favorite language, and post the row back. In other words, a three-step process for each row.

Regexp - back references, translating code from PHP to MySQL

I have a regular expression that works in PHP, but not the MySQL REGEXP function.
'(.)\1{2,}'
In PHP this matches any char that is repeated 2 or more times, how can I translate this to work with the MySQL function.
Sorry, you can't. MySQL uses POSIX regex, which doesn't support back-references. If you must perform such matches in MySQL, your only option is to install a UDF such as lib_mysqludf_preg.