I have a calculation inside a case statement structured like this:
SQRT(POWER()+POWER()+...x84)
That's 84 power functions. I keep getting the error:
Internal error: An expression services limit has been reached. Please look for potentially complex expressions in your query, and try to simplify them.
I understand the limit of identifiers in an expression is 65,535, but mine seemingly doesn't come even close to that. Do the functions change the effective number of identifiers in my expression?
Related
Why is this goal not considered safe?
MANAGER(Name) :- WORKER(Name, Age, _ ), ¬ SUBORDINATE (_, Name), Age <= 40
Our teacher says that it is because SUBORDINATE is negate, and so it can not have undefined (_) spaces, but it seems to be logic for me this expression.
Anyone that can help me?
The safety requirements in Datalog are intended to prevent infinite results. If you have a variable that occurs in the head and only negated in the body, then it can be bound to infinitely many values, which would obviously be a problem.
The specific requirements for safety are hard to precisely formulate, so usually you see the requirements simplified to 'every variable has to occur positively'. This is a bit more restrictive than needed.
The most informative answer to the question would be that the rule is technically unsafe, but that it does not have an infinite result. Some Datalog engines would allows this rule and return the finite result.
This rule is perfectly safe and it does not produce an infinite relation. It is an implementation deficiency of the Datalog engine you are using.
In general, an easy way to handle _ is to convert it into a fresh variable. This makes the implementation of the engine easy, but probably is the reason why this clause throws an error. If it was a variable, there would be an infinite number of values SUBORDINATE's first parameter cannot be.
I receive an invalid floating point operation error when I SQRT(X) a value.
Under which reasons does this error occur, and what could I to to the X value to prevent this error?
For some context, the X value is a calculated average sales for stock items.
I have tried SQRT(ABS(x)) with no luck.
Thanks
As far as I know, the only case when SQRT(X) gives the error "An invalid floating point operation occurred" is when X is negative. However, you already fixed this by using the ABS function like this: SQRT(ABS(X)).
So, my guess is that the error does not really come from the SQRT function but from something else nearby. Let's look at the expression you gave:
SQRT(2*50*ABS(X)) / NULLIF(B*0.2/12,0))
This expression obviously has an extra right parenthesis. This makes me think that it is only a part of a larger expression, and that the larger expression is the reason for the error.
For instance, if B is 0 then the NULLIF() becomes NULL. You divide by NULL, thus getting a NULL result. Now, what do you do with this result? Maybe some more calculations that does not handle the NULL well?
There is a lot of guessing here. If my guesses did not point you in the right direction, then it would be helpful to know which values of B and X that give the error, and also the full statement that includes the expression.
There is a T_SQL command that calculates the type of the variables. You can view the type of variable before calculating its square root.
The command is :
SQL_VARIANT_PROPERTY
(See the site https://blog.sqlauthority.com/2013/12/15/sql-server-how-to-identify-datatypes-and-properties-of-variable/)
On the other hand, I'm sorry to tell you that I do not know if it works with the 2018 version, because I do not have the means to check it. But you can find the equivalent command for your SQL Server version.
Hope that can help.
I have a sql statement (inherited) that has the following WHERE clause:
WHERE
(Users_1.SecurityLevel IN ('Accounts', 'General manager'))
AND (PurchaseOrders.Approval = 1)
AND (PurchaseOrders.QuotedAmount = 0)
AND (Users_1.StaffNumber = ISNULL(ServiceRequests.POC_UserID, PurchaseOrders.Approval_UserID))
OR
(Users_1.SecurityLevel IN ('Accounts', 'General manager'))
AND (PurchaseOrders.QuotedAmount = 0)
AND (ServiceRequests.POC = 1)
AND (Users_1.StaffNumber = ISNULL(ServiceRequests.POC_UserID, PurchaseOrders.Approval_UserID))
OR
(ISNULL(ISNULL(PurchaseOrders.InvoiceNumber, ServiceRequests.InvoiceNumber), '!#') <> '!#')
AND (Users_1.StaffNumber = ISNULL(ServiceRequests.POC_UserID, PurchaseOrders.Approval_UserID))
I'm trying to figure out the order of operations when things are not nicely bracketed.
How are AND and OR statements ordered in the above example?
Is there an easy rule so that I can put brackets around things to make it more readable?
I'm looking for something like "BODMAS" when it comes to the mathematical order of operations, for SQL WHERE clause operators.
Thanks
The page on Operator Precedence tells you:
When a complex expression has multiple operators, operator precedence determines the sequence in which the operations are performed. The order of execution can significantly affect the resulting value.
And that AND has a higher precedence than OR.
However, it's not correct. In SQL, you tell the system what you want, not how to do it, and the optimizer is free to re-order operations, provided that the same logical result is produced.
So, whilst operator precedence tells you how the operators are logically combined, it does not, in fact, control the order in which each piece of logic is actually performed. This means that idioms which may be safe in other languages because of guarantees of execution order are not in fact safe in SQL. E.g. a check such as:
<String can be parsed as an int> && <convert the string to an int and compare to 20>
Can be perfectly safe in languages such as C#. The same logic in SQL is not safe since the optimizer may choose to perform the string to int conversion before it evaluates whether the string can be parsed as an int and so can throw an error about a failed conversion. (Of course, it can also work as you may have expected and not produce an error)
Lets say i have a binary field checked
Lets also assume that 3 documents out of 10 has checked:1 others checked:0
When I search in lucene
checked:1 - returns correct result (3)
checked:0 - returns correct result (7)
-checked:1 - returns correct result (7)
-checked:0 - returns correct result (3)
BUT
-(-(checked:1)) - suddenly returns wrong result (10, i.e. entire data set).
Any idea why lucene query parse acts so weird
Each Lucene query has to contain at least one positive term (either MUST/+ or SHOULD) so it matches at least one document. So your queries -checked:1 and -checked:0 are invalid, and I am surprised you are getting any results.
These queries should (most likely) look like this:
+*:* -checked:1
+*:* -checked:0
Getting back to your problem: double negation makes no sense in Lucene. Why would you have double negation, what are you trying to query?
Generally speaking, don't look at Lucene query operators (! & |) as Boolean operators, they aren't exactly what you think they are.
After some research and trial and error and building up on answer from midas, I have came up with the method to resolve this inconsistency. When I say inconsistency, I mean from a common sense view for a user. From information retrieval prospective, midas has linked an interesting article, which explains why such a query makes no sense.
So, the trick is to keep each negative expression with MatchAllDocsQueryNode class, namely the rewritten query has to look like this:
-(-(checked:1 *:*) *:*)
Then the query will produce the expected result. I have accomplished it by writing my own nodeprocessor class, which performs necessary operations.
I am solving three non-linear equations in three variables (H0D,H0S and H1S) using FindRoot. In addition to the three variables of interest, there are four parameters in these equations that I would like to be able to vary. My parameters and the range in which I want to vary them are as follows:
CF∈{0,15} , CR∈{0,8} , T∈{0,0.35} , H1R∈{40,79}
The problem is that my non-linear system may not have any solutions for part of this parameter range. What I basically want to ask is if there is a smart way to find out exactly what part of my parameter range admits real solutions.
I could run a FindRoot inside a loop but because of non-linearity, FindRoot is very sensitive to initial conditions so frequently error messages could be because of bad initial conditions rather than absence of a solution.
Is there a way for me to find out what parameter space works, short of plugging 10^4 combinations of parameter values by hand and playing around with the initial conditions and hoping that FindRoot gives me a solution?
Thanks a lot,