How to use Wild card in where clause? - where-clause

I am using below query to shunt ORA-00001 from set of log files. this query works fine for just one log file.
index=xyz* NOT [search index=xyz* "ORA-00001" | WHERE source="/logs/sit/camel-audit.log"]
but when I put wild card in where clause, it doesn't work.
index=xyz* NOT [search index=xyz* "ORA-00001" | WHERE source="/logs/*/camel-audit.log"]
Could you please help me on how to use wild card in where clause?

In order to take advantage of wildcards in Where clause, you can use LIKE operator for comparison.
Eg. WHERE source LIKE "/logs/%/camel-audit.log"]
Note that the equals operator does not support wildcard comparison.
Also note the use of '%' as a wildcard character instead of '*'. '%' denotes multiple characters.
This link - http://www.w3schools.com/sql/sql_wildcards.asp might be helpful.

Related

Effectively handling wildcard characters in Sybase

I have this query in our legacy application -
Select * from Customers where Name like ('param')
Problem is when UI user passes param=%, it shows all available customers. Which we want to avoid.
when param = [abc] , it shows all the customers with a,b or c in thier names. We want to avoid this as well.
In fact we want to handle all sort of wild card character searched to avoid SQL Injection.
In java script what is the way I can achieve this, so that I pass only valid Param to my server.
Pay attention to below query:
Select * from Customers where Name like N'%param%'
Instead of like, use =:
where Name = 'param'
= is a lot like like except it doesn't have wildcards -- That is a bit of a joke. You don't want wildcards so don't use the operator that relies on them.

How do I use wildcard to find a register ignoring spaces in the position of the wildcard in MS Access SQL?

I have two or more different registers in my database, as follow:
EMEAFRANKFURTPDEDHuman Resourcesexpat immigrationApplication
and
EMEAFRANKFURT NBEUAGITCLS (GUI)Application
I would like to find any register that is like EMEAFRANKFURT but excluding registers with any space after the word FRANKFURT.
If I use WHERE [FIELD] IS LIKE "EMEAFRANKFURT*" it won't ignore the space.
So in summary my question is, how do I ignore the space?
Thank you,
You can use the inverse range operator to do it in a single filter operation:
[FIELD] LIKE "EMEAFRANKFURT[! ]*"
Note that this requires at least one character after EMEAFRANKFURT. If that's undesirable, you can use [FIELD] LIKE "EMEAFRANKFURT[! ]*" Or [FIELD] = "EMEAFRANKFURT"
Well, after thinking about I got the solution.
I used another table that contains the same field and perform a right join and then I used the criteria as follow:
In the left table:
Like 'EMEAFRANKFURT*'
In the right table
Not Like 'EMEAFRANKFURT *'
So it is ignoring all matches with the left table that contains a space after the word FRANKFURT.
However, is there any other solution that isn't use a right join?

In a Rails WHERE LIKE query, what does the percent sign mean?

In a simple search like this:
find.where('name LIKE ?', "%#{search}%")
I understand that #{search} is just string interpolation. What do the % symbols do?
The percent sign % is a wildcard in SQL that matches zero or more characters. Thus, if search is "hello", it would match strings in the database such as "hello", "hello world", "well hello world", etc.
Note that this is a part of SQL and is not specific to Rails/ActiveRecord. The queries it can be used with, and the precise behavior of LIKE, differ based on SQL dialect (MySQL, PostgreSQL, etc.).
search = 'something'
find.where('name LIKE ?', "%#{search}%")
In your DB it will be interpreted as
SELECT <fields> FROM finds WHERE name LIKE '%something%';
The percent sign in a like query is a wildcard. So, your query is saying "anything, followed by whatever is in the search variable, followed by anything".
Note that this use of the percent sign is part of the SQL standard and not specific to Rails or ActiveRecord. Also be aware that this kind of search does note scale well -- your SQL db will be forced to scan through every row in the table trying to find matches rather than being able to rely on an index.

Lucene Query Syntax of field with a space

I am trying to perform two Lucene queries. The first one works. The second does not. My first query looks like this:
level:"dangerous"
My second query looks like this:
IP address:"11.22.333.444"
I'm not getting a query error. However, I know there are documents with the matching IP address. For that reason, I suspect the space between "IP" and "address" is causing the problem. However, I'm not an expert in Lucene. So, I'm not sure if I'm correct in that.
When I look at my result set using PostMan, I can see a document with a field that looks like this:
"IP address": "11.22.333.444"
Can someone please tell me if my query is correct? Or, if I'm missing something?
Thank you!
Yes, that space is the problem.
The space in a field name is allowable, but conflicts with query parser syntax. You are essentially running two subqueries combined as SHOULD clauses (ie, an OR):
IP
address:"11.22.333.444"
You can escape the space using a single slash before the space, like:
IP\ address:"11.22.333.444"

How to implement "like" in BigQuery?

I am trying to run a simple query making a restriction of like % in BigQuery, but LIKE is not in their syntax, so how can it be implemented?
You can use the REGEXP_MATCH function (see the query reference page):
REGEXP_MATCH('str', 'reg_exp')
Instead of using the % syntax used by LIKE, you should use regular expressions (detailed syntax definition here)
LIKE is officially supported in BigQuery Standard SQL -
https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#comparison_operators
And I think it also works in Legacy SQL!
REGEXP_MATCH returns true if str matches the regular expression. For string matching without regular expressions, use CONTAINS instead of REGEXP_MATCH.
https://developers.google.com/bigquery/docs/query-reference#stringfunctions
REGEXP_MATCH is great if you know how to use it, but for those who aren't sure there won't be any commonly used special characters such as '.','$' or '?' in the lookup string, you can use LEFT('str', numeric_expr) or RIGHT('str', numeric_expr).
ie if you had a list of names and wanted to return all those that are LIKE 'sa%'
you'd use:
select name from list where LEFT(name,2)='sa'; (with 2 being the length of 'sa')
Additionally, if you wanted to say where one column's values are LIKE another's, you could swap out the 2 for LENGTH(column_with_lookup_strings) and ='sa' for =column_with_lookup_strings, leaving it looking something like this:
select name from list where LEFT(name,LENGTH(column_with_lookup_strings))= column_with_lookup_strings;
https://cloud.google.com/bigquery/query-reference