In Informix:
how to check for not null,
I have a field with datetime data type, and I don't have any default values for this field, but I have lot of empty/null records for this field.
I want a query that will render the records:
( cond like ) where my_curr_date_time != ""
but if I try this query, it is not working. Please tell which query for finding not null records.
... WHERE my_curr_date_time IS NOT NULL
NULL is a special value. It may mean "no value" or "value unknown". In SQL if you want to check if value is or not is NULL then you must use ... yes ... value IS NULL or value IS NOT NULL. It may be used with other conditions like:
... WHERE my_curr_date_time IS NOT NULL AND my_curr_date_time > start_dt
Related
In a postgres database I have a string field code in orders table. The field contains values like 'COA-38-A', 'EFILLDIRT' and 'HE60LS-A'. There is a form on UI to filter orders based on code and only integer values are allowed in the field.
The query should filter the orders by integer values in the code field i.e if 30 is entered, the query should return orders with code 'COA-38-A' and 'HE60LS-A' because the query contains >=
I tried adding ::integer in the query:
Order.where('code::integer >= ?', params[:code])
but got the following error:
PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer
Is there any way to filter by only integer values?
try this?
Order.where("regexp_replace(0||code, '[^0-9]+', '', 'g')::integer >= ?", params[:code].to_i)
I have a cypher query as follows:
MATCH (u:User {uid:"984172414"})-[ru:EB]->
(c:Co)<-[rf:EB]-(f:User)-[rc :EB]->(cc:Co)
WHERE (cc.uid in ["84161623"]) AND (rc.from IS NOT NULL AND rc.to IS NULL) AND
((
ru.from IS NOT NULL AND
ru.to IS NOT NULL AND
(
(rf.from <= ru.to) OR
(ru.from <= rf.to)
)
) OR (
ru.from IS NOT NULL AND
ru.to IS NULL AND
(
(ru.from <= rf.to) OR
(rf.from IS NOT NULL AND rf.to IS NULL)
)
) OR (
ru.from IS NULL AND
ru.to IS NOT NULL AND
(
(rf.from <= ru.to) OR
(rf.from IS NULL AND rf.to IS NOT NULL)
)
))
RETURN cc.name as coname,
f.name as fname,
cc.uid as cuid,
f.uid as fuid,
labels(f) as flabels,
null as version
LIMIT 20
This takes about 16192 ms to resolve. I have an index on co.uid but seems like it's not working. If I remove the check cc.uid in ["84161623"] and run the following query:
MATCH (u:User {uid:"984172414"})-[ru:EB]->
(c:Co)<-[rf:EB]-(f:User)-[rc :EB]->(cc:Co)
WHERE (rc.from IS NOT NULL AND rc.to IS NULL) AND
((
ru.from IS NOT NULL AND
ru.to IS NOT NULL AND
(
(rf.from <= ru.to) OR
(ru.from <= rf.to)
)
) OR (
ru.from IS NOT NULL AND
ru.to IS NULL AND
(
(ru.from <= rf.to) OR
(rf.from IS NOT NULL AND rf.to IS NULL)
)
) OR (
ru.from IS NULL AND
ru.to IS NOT NULL AND
(
(rf.from <= ru.to) OR
(rf.from IS NULL AND rf.to IS NOT NULL)
)
))
RETURN cc.name as coname,
f.name as fname,
cc.uid as cuid,
f.uid as fuid,
labels(f) as flabels,
null as version
LIMIT 20
The query resolves in only 347 ms. I can't figure out what is wrong with the (cc.uid in ["84161623"]) statement and why does adding this to the query takes 16 seconds to resolve when I already have an index on the uid. Any help will be appreciated.
update
As suggested by #cybersam I tried making the use of USING INDEX but that results in the following error:
Cannot use index hint in this context. Index hints require using an equality comparison or IN condition in WHERE (either directly or as part of a top-level AND). The comparison cannot be between two property values. Note that the label and property comparison must be specified on a non-optional node
Try using a USING INDEX clause to provide a hint to use that index. The Cypher processing code does not always automatically generate the most efficient code.
For example, put this between the MATCH and WHERE clauses:
USING INDEX cc:Co(uuid)
You may also need to use additional USING INDEX clauses if there are other indices. Note, however, that neo4j can not use indices in all situations; and, even if it is possible, the resulting query could theoretically be slower due to other resulting changes to the query. So, take a look at the resulting profile and test the result to make sure you are happy with it.
Sounds like you may need to do some sanity checking.
First of all, is :Co.uid an int or a string? It looks like you're addressing it as if it's a string, yet the values themselves look numeric. If it's an int, you can get rid of the quotes.
Same with :User.uid.
If you've been comparing ints to strings all this time, try fixing that first to see if it solves the problem. If not, you'll want to start profiling and figuring out if/when the query isn't using your index.
Next, try simplifying and profiling the query to see if the indices are actually being used:
PROFILE MATCH (u:User {uid:"984172414"}), (cc:Co)
WHERE (cc.uid in ["84161623"])
RETURN u, cc
If they're both using NodeIndexSeek or NodeUniqueIndexSeek, and if the db hits seem reasonable, you might expand out to your entire path and continue profiling. However, it's worth checking for a performance improvement if you match on the start and end nodes first, like above, then try to do your additional pattern matching. For example:
PROFILE MATCH (u:User {uid:"984172414"}), (cc:Co)
WHERE (cc.uid in ["84161623"])
WITH u, cc
MATCH (u)-[ru:EB]->(c:Co)<-[rf:EB]-(f:User)-[rc :EB]->(cc)
WHERE (rc.from IS NOT NULL AND...
i have a store procedure,its meant for updating a table,when i execute it,it brings out nulls or zero values for a some columns.this is the logic used
IF OBJECT_ID('tempdb..#exxPresessions_john') IS NOT NULL
DROP TABLE #exxPresessions_john
SELECT c.claim_id,
c.completed_date,
wp.createdon,
COUNT(DISTINCT wp.WebSessionId) AS websessions
INTO #exxPresessions_john
FROM dbo.web_PageviewsID wp WITH (NOLOCK)
JOIN #CliamID_john c WITH (NOLOCK)
ON c.claim_id = wp.claimid
WHERE ClaimType IS NOT NULL
AND c.completed_date > wp.createdon
GROUP BY
claim_id,
completed_date,
createdon
ORDER BY claim_id;
CREATE INDEX idx_index2 ON #WebPresessions_nosa (claim_id);
this is the Condition
completed_date > created_date
.it returns NULL as completed_date is NULL or Zero
i tried this but it did not work
and ISNULL (c.completed_date,0)> wp.createdon
You need to add one more condition like this:
WHERE ClaimType IS NOT NULL
AND c.completed_date is not null --Removes the null completed_date
AND c.completed_date > wp.createdon
var query = EntityQuery.from('Cases')
.where("ID", "==", id);
When I try to execute the above query for an ID value, it returns null value for 2 columns and the record in the table does contain values for it. The columns are string.
return datacontext.getCase(caseID, vm.caseObj).then(function () {
alert(vm.caseObj().AuditTypeCd());
});
caseID is a global variable which contains the desired ID. If I replace that with a constant value of any ID (10 or any other ID), I see that the property AuditTypeCd is fetched.
The query returns null value for few columns when global variable caseID is used. A very strange behavior.
I'm writing triggers to detect changes in fields in a database, and it appears I have to do really obnoxious things like
(SELECT SalesPrice FROM __old) <> (SELECT SalesPrice FROM __new)
or ((SELECT SalesPrice FROM __old) IS NULL and (SELECT SalesPrice FROM __new) IS NOT NULL)
or ((SELECT SalesPrice FROM __old) IS NOT NULL and (SELECT SalesPrice FROM __new) IS NULL)
rather than just
(SELECT SalesPrice FROM __old) <> (SELECT SalesPrice FROM __new)
to accurately detect if a field changed.
Am I missing something, or does Advantage effectively claim that NULL == any value? Is there a good reason for this behavior? Is this some weird thing in the SQL definition? Is there a more succinct way this that doesn't do 3 checks in place of one?
This is unfortunately how SQL works with NULL values. NULL is not equal to anything, it is UNKNOWN. For example,
somevalue == NULL -> unknown
somevalue <> NULL -> unknown
As a result it will never pass a "true" check
Null Values - Wikipedia
There are a couple of options:
A) Do not allow null values (I recommend combining this with a default value)
B) Use IFNULL to set the field to some value such as
(SELECT IFNULL(SalesPrice, -9999) FROM __OLD) <> (SELECT IFNULL(SalesPrice, -9999) FROM __NEW)
But I don't know if I necessarily like this since a value must be picked that would not be valid.
In SQL, NULL does not compare to anything, except the IS [NOT] NULL expression. If I understand you question correctly, the problem here is that NULL must equal to NULL. If that is the case, the check may be simplified to:
( SELECT CASE WHEN n.SalesPrice IS NULL and o.SalePrice IS NULL THEN TRUE
ELSE n.SalesPrice = o.SalesPrice END
FROM __old o, __new n )