Informix Accent Insensitive Search - sql

Is there any way (a function, a config option, etc.) to force informix to ignore accents on searches?
Example:
select id, name from user where name like 'conceição%'
Returns:
1 | conceicao oliveira
2 | conceiçao santos
3 | conceicão andrade
4 | conceição barros
Thanks

Not directly, that I'm aware of. You could install the Regex DataBlade module. The use it's regexp_match function. Replacing the query with something like this:
where regexp_match(name , 'concei[çc][ãa][o]%')
Or, if you don't have that option, what I would do would be add another 'normalized_name' column. replacing all the accented characters with a "standard" character. Then query my table based on that.
name='conceiçao santos', normalized_name='conceicao santos'
Adding a normalized column will also make sure you're not dependant on any module, or any particular database for that matter.

Related

SQL Server LIKE caret (^) for NOT does not work as expected

I was reading the article at mssqltips and wanted to try the caret in regex. I understand regex pretty well and use it often, although not much in SQl Server queries.
For the following list of names, I had thought that 1) select * from people where name like '%[^m]%;' will return those names that do not contain 'm'. But it doesn't work like that. I know I can do 2) select * from people where name not like '%m%'; to get the result I want, but I'm just baffled why 1) doesn't work as expected.
Amy
Jasper
Jim
Kathleen
Marco
Mike
Mitchell
I am using SQL Server 2017, but here is a fiddle:
sql fiddle
'%[^m]%' would be true for any string containing a character that is not m. An expanded version would be '%[Any character not m]%'. Since all of those strings contain a character other than m, they are valid results.
If you had a string like mmm, where name like '%[^m]%' would not return that row.

SQL Server Like Pattern

I want to match custom pattern in one of the column in a SQL Server database. The problem is I don't know the exact pattern length.
I want only those rows which has 'function' and 'alphanumeric pattern' which has min 5 and max 8 characters. Starting and ending characters are not fixed, not case sensitive.
Column value looks like this:
Row Value
--------------------------------------------------------------------
1 I have a single own function and its namely 123BA689,BAS54256
2 Everyone has base function AFD12,CHD12234
3 Nicole has its own ASS1256902,25ADFG2
Desired output:
Row Value
--------------------------------------------------------------------
1 I have a single own function and its namely 123BA689,BAS54256a
2 Everyone has base function AFD12,CHD1223465AS
I have tried Like and regex to match pattern but failed.
Does anybody know how to fix it?
select *
from ab
where lower(ab.a) like '%function' and '%[a-z0-9]{6}%'
Thanks.
SQL Server doesn't support regular expressions. You could conceptually do what you want with:
where lower(ab.a) like '%function%' and
lower(ab.a) like '%[a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9]%' and
lower(ab.a) not like '%[a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9]%'
However, this will return any string that has "function", because that is an alphanumeric patter with 5-8 characters.

SQL LIKE - Using square bracket (character range) matching to match an entire word

In REGEX you can do something like [a-c]+, which will match on
aaabbbccc
abcccaabc
cbccaa
b
aaaaaaaaa
In SQL LIKE it seems that one can either do the equivalent of ".*" which is "%", or [a-c]. Is it possible to use the +(at least one) quantifier in SQL to do [a-c]+?
EDIT: Just to clarify, the desired end-query would look something like
SELECT * FROM table WHERE column LIKE '[a-c]+'
which would then match on the list above, but would NOT match on e.g "xxxxxaxxxx"
As a general rule, SQL Server's LIKE patterns are much weaker than regular expressions. For your particular example, you can do:
where col not like '%[^a-c]%'
That is, the column contains no characters that are not a, b, or c.
You can use regex in SQL with combination of LIKE e.g :
SELECT * FROM Table WHERE Field LIKE '%[^a-z0-9 .]%'
This works in SQL
Or in your case
SELECT * FROM Table WHERE Field LIKE '%[^a-c]%'
I seems you want some data from database, That is you don't know exactly, You must show your column and the all character that you want in that filed.

sql query words that don't have numbers?

It is possible to select just words that don't contain numbers?
Something like...
|Address |
-----------------
|Street x 150 |
|Street y |
|Street z 498Z |
I want just Street y in this case.
I have these texts in a excel, and would 'filter' in access. And in last try I can pass it to a SQL Server (microsoft).
I'll search about REGEX on Access or mssql.
Here is a way to do it in SQL Server (and most other databases):
select *
from t
where address not like '%[0-9]%'
That is, the address is not like something that has a number in it.
Like in Access does not follow the standard at all (using * rather than % as the wildcard, for instance). So, this will not work in Access.
SELECT ... FROM ...WHERE fieldname REGEXP [^0-9]

sql complex like expression #user

im trying to find all the mentions for the matched username (sam) from the database text code with following:
$sql = "select * from tweet where feed like '%#sam%'";
this will return all the rows which user have been mention at.
but now the problem is, it also returns rows with #sam3, #sam-dadf or anything that is after #sam..
how can i limit this, so only specific username shows from the text and not all the matching sams.. following are the text format in the database, that is inserted in feed row.
1. i been out with #sam today, but im
not sure what we should do
2. we head great party today and all the frineds were invited, such as #sam, #jon, #dan...
3. i been out today with #samFan and with #dj. << this row should not get pull from database``
Yes, use REGEXP (or RLIKE), but watch out for the common regex mistake of looking for the end of the desired "token" as merely a common, negated character class like [^A-Za-z0-9] -- instead use the zero-width, "end of word" match construct [[:>:]] (which perl's engine and other inspired regexen know as \b).
The negated character class fails to match at the end-of-string:
mysql> SELECT 'I am #sam' REGEXP '#sam[^A-Za-z0-9]' AS "Does This Match?";
+------------------+
| Does This Match? |
+------------------+
| 0 |
+------------------+
1 row in set (0.00 sec)
where the word boundary match succeeds:
mysql> SELECT 'I am #sam' REGEXP '#sam[[:>:]]' AS "Does This Match?";
+------------------+
| Does This Match? |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
If [[:>:]] isn't quite right for your application (because your "username" character set is not what the MySQL regex engine thinks of as one side of a word boundary in your locale), you can, alternatively, specify a negated character class and separately test for end-of-string:
SELECT ... WHERE (feed REGEXP '#sam[^A-Za-z0-9]' or feed REGEXP '#sam$')
I would recomend using mysql regular expression to try to achive this.
Search the string sfor your required text, disregarding selected followup chars
MySQL Regular Expressions
I'm sorry, but I'm not familiar with MySql.
In Microsoft SQL Server, the Like clause can allow you to specify fields to NOT match.
Ex:
if ('I like #Spam.' LIKE '%#Spam[^a-z]%') SELECT 1
select * from table where feed REGEXP '#sam[^A-Za-z0-9]'