In SQL, we can perform the following in the where clause:
SELECT * FROM tbl WHERE :parameter <> '' OR :parameter is not null
Is this possible in elastic search to check if the input parameter/value is not null or empty? I checked the exists query but the parameter is a field, not a value.
You can use SQL API or using Exists Query.
Ex:
POST /_sql?format=txt
{
"query": "SELECT * FROM bar WHERE Id <> '' AND Id is not null"
}
Related
I want to be able to let the business manually enter a USERID into a parameter box or leave it blank for it to bring back all USERID's.
I have setup another parameter for CUSTOMERID which uses a dataset to bring back a list of customer ID's. Due to the amount of USERID's I don't want to use the same solution but instead have them manually enter the USERID or leave it blank and bring back ALL.
SELECT
CUSTOMERID,
CASE
WHEN STATUSCODE = 200 THEN 'Successful Logon'
ELSE 'Unsuccessful Logon'
END as LogonStatus,
COUNT( * ) COUNTOFACCOUNTS
FROM
MA4EQNG.APPLICATIONLOG
WHERE
CUSTOMERID in ('"+join(Parameters!CustomerID.Value, "','")+"')
AND (Cast(DATETIME as Date) >= '"& Format(Parameters!FromDate.Value, "yyyy-MM-dd") & "'
AND Cast(DATETIME as Date) <= '" & Format(Parameters!ToDate.Value, "yyyy-MM-dd") & "')
AND COMPONENTDESCRIPTION = '/eq/auth/v1/logon'
AND METHOD = 'POST'
GROUP BY
CUSTOMERID,
CASE
WHEN STATUSCODE = 200 THEN 'Successful Logon'
ELSE 'Unsuccessful Logon'
END
ORDER BY
CUSTOMERID ASC
Please let me know if you need anything else.
You can set the USERID parameter to allow blank value then use IF condition on your main dataset sql script.
Try
IF LEN(#USERID)>0
*put the sql script with UserId filter in where clause*
ELSE
*put the sql script WITHOUT UserId filter in where clause*
Normally you would just script something like this in the WHERE clause.
WHERE
isnull(#CustomerID,'') = '' OR (CUSTOMERID in('"+join(Parameters!CustomerID.Value, "','")+"'))
And long term, I would create a function that takes in a delimited string, and converts them to rows, then you can just join on the results from the table valued function.
How to split a comma-separated value to columns
Let's say I have a jsonb column type called "data" for the table "recipes". I'm trying to find all records that have "data" filled out (i.e. "data" is not null or an empty bracket {}).
I know for hstore columns, using ruby, you can use a query like this to do so:
Recipe.where("data <> ''")
Is there an equivalent query for jsonb?
Updated after reading the question properly:
You can check for columns with NO data like this
SELECT * FROM table WHERE json_column IS NOT NULL
So this would then be
Recipe.where.not('data IS NULL')
And for columns with non-empty hashes like this:
SELECT * FROM table WHERE json_column <> '{}'
This translates to:
Recipe.where('data <> ?', '{}')
# or
Recipe.where("data <> '{}'")
A good way to verify your query is to run them in SQL first (so you avoid AR and its translation of Ruby to SQL). Then you can try and build the query in AR and use to_sql to see what AR makes of your queries.
Recipe.where('data <> ?', '{}').to_sql
#=> "SELECT \"recipies\".* FROM \"recipies\" WHERE (data <> '{}')"
vs.
Recipe.where('data <> ?', {}).to_sql
#=> "SELECT \"recipies\".* FROM \"recipies\" WHERE (data <> NULL)"
I am trying to return a list of cell phone numbers from the S_CONTACT table of Siebel where the value contains anything other than numbers.
The query I am using is:
select cell_ph_num
from s_contact
where regexp_replace(cell_ph_num, '0|1|2|3|4|5|6|7|8|9', '') <> ''
But I get no results.
However, when I run the following query:
select regexp_replace(cell_ph_num, '0|1|2|3|4|5|6|7|8|9', '') from s_contact
I get a load of results.
Do these results not match the "does not equal empty string" clause?
'' is NULL in oracle.. so it has to be IS NOT NULL
select cell_ph_num
from s_contact
where regexp_replace(cell_ph_num, '0|1|2|3|4|5|6|7|8|9', '') IS NOT NULL
OR We can use REGEXP_LIKE this way by POSIX class
WHERE REGEXP_LIKE (cell_ph_num,'[^[:DIGIT:]]');
OR Perl style POSIX equivalent
WHERE REGEXP_LIKE (cell_ph_num,'\D');
I'm trying to implement https://stackoverflow.com/a/16392399/14731 for a table called "Modules" using QueryDSL. Here is my query:
String newName = "MyModule";
QModules modules = QModules.modules;
BooleanExpression moduleNotExists = session.subQuery().
from(modules).where(modules.name.eq(newName)).notExists();
SimpleSubQuery<String> setModuleName = session.subQuery().
where(moduleNotExists).unique(Expressions.constant(newName));
long moduleId = session.insert(modules).set(modules.name, setModuleName).
executeWithKey(modules.id);
I am expecting this to translate into:
insert into modules(name)
select 'MyModule'
where not exists
(select 1 from modules where modules.name = 'MyModule')
Instead, I am getting:
NULL not allowed for column "NAME"; SQL statement:
insert into MODULES (NAME)
values ((select ?
from dual
where not exists (select 1
from MODULES MODULES
where MODULES.NAME = ?)))
where ? is equal to MyModule.
Why does QueryDSL insert from dual? I am expecting it to omit from altogether.
How do I fix this query?
For the insert into select form use
columns(...).select(...)
But your error suggests that the INSERT clause is valid, but semantically not what you want.
Using InsertClause.set(...) you don't get the conditional insertion you are aiming for.
In other words with
columns(...).select(...)
you map the full result set into an INSERT template and no rows will be inserted for empty result sets, but with
set(...)
you map query results to a single column of an INSERT template and null values will be used for empty results.
Query:
select *
from easquestionsinfo
where questionname in(select questionname
from easresponseinfo
where isconflict = 'yes')
This query works fine and returns me the records from table 'easquestioninfo' when questionname is equal to the one returned by the inner query which returns set of questionname where isconflict='yes'.
JPA supports JPQL, SQL, and Criteria.
You can execute this SQL directly using createNativeQuery().
For JPQL, it depends on your object model, perhaps something like,
Select q fom QuestionInfo q where q.name in (Select r.name from ResponseInfo q2 where r.isConflict = 'yes')
See,
http://en.wikibooks.org/wiki/Java_Persistence/JPQL