OrientDB COALESCE Function With Unexpected Results - orientdb

Using OrientDB 2.1.2, I was trying to use the inherent COALESCE functionality and ran into some strange results.
Goal: select the maximum value of a property based on certain conditions OR 0 if there is no value for that property given the conditions.
Here's what I tried to use to produce my results.
Attempt 1: Just selecting the Maximum value of a property based on some condition - This worked as I expected... a single result
Attempt 2: Same query as before but now I'm adding an extra condition that I know will cause no results to be returned - This also worked as I expected... no results found
Attempt 3: Using COALESCE to select 0 if the result from the second query returns no results - This is where the query fails (see below).
I would expect the result from the second query to return no results, thereby qualifying as a "NULL" result meaning that the COALESCE function should then go on to return 0. What happens instead is that the COALESCE function is seeing the results of the inner select (which again, returns no results) as a valid non-null value, causing the COALESCE function to never return the intended "0" value.
Two questions for those who are familiar with using the OrientDB API:
Do you think this functionality is working properly or should an issue be filed with the orientdb issue tracker?
Is there another way to achieve my goal without using COALESCE or by using COALESCE in a different way?

Try rather:
select coalesce($a, 0) from ... let $a = (subquery) where ...
Or also this variant because the sub-select returns a result set, but the coalescence wants a single value:
select coalesce($a[0], 0) from ... let $a = (subquery) where ...

Related

Optional where condition with List input variable

I'm trying to ignore condition when the input is null. There are already a lot of threads on stackoverflow dealing with this situation but I've not been able to find one with a List input variable.
The mentionned solution does not work as IN null raises an error. That's why I added a COALESCE :
:toto type : List<Integer>
SELECT *
FROM test_table
WHERE (:toto is null OR year IN (COALESCE(:toto, (1, 2))))
Problem is that COALESCE itself returns an error :
COALESCE types bytea and record cannot be matched
Strangest thing is that this query is working with a null input if I'm making a raw query directly onto the database. I'm suspecting JPA to don't give a real null value to :toto.
Any solution leading to make index working and providing the correct behavior would be ok.

Tableau LOD (i think)

I am trying to create a visualisation where i can see where a product has passed 2 tests: test=overall and test=flash (these are part of the same column). then there is a column result which can be pass/fail. i want both of these tests to be pass and then i want to count the distinct products. I then want to include this figure in a dashboard that updates.
I think I want a LOD but not sure where to start. is this something i do in desktop or prepenter image description here
I am new to Tableau so LOD is something i am trying to get my head around
Use the below calculation,
if {fixed [Device]: min([Result])}='fail' then False else TRUE end
Pull this field to filter shelf and select TRUE to get only devices which pass both tests
You didn’t say how to treat devices that have both pass and fail entries for one of your tests. This expression tests whether a device has passed at least one overall test and at least one flash test. You could also use a version of this to define a set if you preferred
{ fixed [Device] : max([test] = “overall” and [Result] = “pass”) and
max([test] = “flash” and [Result] = “pass”) }
The key concept is that MIN() and MAX() operate on boolean arguments to return boolean values, treating True values and greater than False values. So MAX() tests whether the condition is ever satisfied; i.e. it returns true if the condition evaluates to true for at least one of the data records. Likewise, MIN() tests whether the condition is always satisfied; i.e. it returns true if the condition evaluates to true for every one of the data records.
If the condition ever evaluates to null, MIN() and MAX() ignore null values just like all other aggregation functions. So if that is an issue in your case, you can use IFNULL() around your expression to provide a default value.

Postgres COALESCE inside nullif for 2 different fields

I am new to SQL and POSTGRES and had a quick question. Right now I have 2 different tables one with car info and one with partial car info and I would like to sort on car.vin OR partial_car.vin depending if either exists and sending all nulls/empty strings to the end of the sort. Currently my ORDER BY statement looks like:
ORDER BY nullif(coalesce(car.vin, partial_car.partial_vin), '') asc nulls last limit 50 offset 0
My expectation for this is that coalesce will take the first non null value and use that for sorting or it will return null and send that to the end. My results so far I haven't been able to make sense of. There are null values being placed in between actual values etc.. If I make this change coalesce(car.vin, '') again I see it work properly. Anyone have an ideas as to why this is the behavior? Let me know if you need something more from me.
It was human error on my end. The object being sent to client was not being populated properly with partial data. So sorting was correct but was seeing blanks due to those values not being present.

How to get all data without any filtering in "in" clause

As a part of reporting I want to get some values from database.
Also I included filtering in report UI, like :
select * from invoice where id in (92)
So I am making the postgres statement dynamically(here 92 is the value getting from UI and assigning dynamically). But I want to return all data without any condition if the user select no option, id in this case (no filtering). So how can I handle the "in" clause to return all data without any filtering in this case.
I am asking for a common term that can be included in 'in' clause, so it retun all rows without filtering.
Thanks!
One method is using logic like:
where (v_id is null) or (id = v_id)
Note: be careful about the use of in. It probably will not do what you intend if you expect multiple values to match.

SQL0100W Error on DB2

I get the following error when running an sqr report on DB2:
SQL0100W - No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. SQLSTATE=02000
The sql in question runs correctly when I paste it into RapidSQL, replacing the parameters. The sql in question is an insert-select. No rows are returned by the select, and this is fine... I expect the report to be blank for my parameters.
Any idea how I can get around this?
DB2 returns always an SQL0100 warning (this is a warning, not an error - errors would have negative values) when no rows are returned. That's the way it is.
I don't know peoplesoft at all - so I can't give you any pointers with that. Back when I was programming for DB2 we ignored those SQL0100 warnings.
If SQR can't gracefully handle a NOT_FOUND SQL0100 return, then code a preliminary query to return a count of the number of rows that satisfy the conditions of the actual query. Check the result of the count in an if-then block in SQR to run the actual query if and only if the row count returned by the preceding query was not zero.
Turns out to be an environment setup issue. Got resolved with no change from me after a couple of builds....
Strange :-/
if you delete delete more than one record using logic operation like delete from tabname where columnnmae=deleterecord and columnnmae=deleterecord then they show this type error.machine an