In XQuery, I want to sum values that are not null (effectively count null as 0). I've tried the following without success.
sum(data(//Line/Total))
I get this error
Cannot cast untypedAtomic: to double
How can I do this in one step?
sum(data(//Line[Total !='']/Total))
Sample XML:
<Order>
<Line>
<Total>1</Total>
</Line>
<Line>
<Total>1</Total>
</Line>
<Line>
<Total></Total>
</Line>
</Order>
Use a predicate to ensure that only the values that can be evaluated as a number() are included in the sum(). Ensure that the number() value is equal to it's number() value, since NaN will not equal NaN.
sum(/Order/Line/Total[number() = number()])
Or ensure that the value is castable as xs:double
sum(/Order/Line/Total[. castable as xs:double])
An empty value (if not defined more specifically through XML schema) has no specific type attached and thus the very general type untypedAtomic. From this, no type can be derived -- that's why you get the error message it cannot be casted.
You have to exclude those empty values somehow. #Mads Hansen proposed filtering for those elements that can be casted as xs:double, which is a very elegant solution, which I would go for. To just remove empty values, you could also test for elements not having any data stored:
sum(/Order/Line/Total[data()])
but be aware of elements containing strings that cannot be parsed as numbers, whitespace not removed, ...
This might be a case where using the text nodes rather than the elements is convenient: sum(/Order/Line/Total/text()).
Related
Hi, I'm pretty new to gamemaker and I'm trying to set a variable (global.b1) to the first value of "global.level_data". For example, global.b1 will be set to mimic the blue outline of "global.level_data"'s first value, which is 0. Can anyone tell me how to do this?
If I look at it correctly, you want to get the first value of an array
I think this should suffice:
global.level_data = [0,0]
global.b1 = global.level_data[0];
It may look confusing if you're not familiar with how arrays work, but the [0] represents the first value of the array (which happens to be 0 as well). The count of arrays also starts with 0 instead of 1.
For further understanding about arrays, I recommend reading this: https://manual.yoyogames.com/GameMaker_Language/GML_Overview/Arrays.htm
And as a side note: if you're creating new variables, the values in that variable will usually not update it's original form (e.g. changing the value global.b1 will not change the value in global.level_data[0] unless you set that yourself).
If you prefer the latter, then I think you're better off using global.level_data[0] for getting and setting directly
I know truncating data means a column has less capacity.
But in my case, all I'm doing is to change the nullability of a numeric column, that has no value at all.
I'm using MariaDB + Adminer. I have not executed an insert query. I just used Adminer to change the nullability of a column named Order.
How is this error even possible? What does it mean in this context?
This error usually happens if a column type will be changed and existing values cannot be converted without truncation:
e.g Changing INT to TINYINT (and column has values > 0xFF)
changing to NOT NULL if column has NULL values
shrinking of CHAR/BLOB
..
If you're ok with any truncation (which might end up in loss of data and/or integrity) use ALTER IGNORE TABLE
They are described as scalar, but I think that refers to the return type rather than the arguments.
I'm trying to define one in rust that will provide a TEXT value derived from other columns in the row, for convenience/readability at point of use, I'd like to call it as select myfunc(mytable) from mytable rather than explicitly the columns that it derives.
The rusqlite example simply gets an argument as f64, so it's not that clear to me how it might be possible to interpret it as a row and retrieve columnar values from within it. Nor have I been able to find examples in other languages.
Is this possible?
This doesn't seem possible.
func(tablename) syntax that I'm familiar with seems to be PostgreSQL-specific; SQLite supports func(*) but when func is user-defined it receives zero arguments, not one (structured) or N (all columns separately) as I expected.
In R for Everyone by Jared P. Lander on p. 54 it says "...NULL is atomical and cannot exist within a vector. If used inside a vector, it simply disappears."
I understand the concept of being atomic is being indivisible and that NULL represents "nothingness", used commonly to handle returns that are undefined.
Therefore, is NULL atomical b/c it has this one value always of "nothingness", meaning something simply does not exist and therefore R's way of handling that is to just not let it exist in a vector or on assignment in a list it will actually remove that element?
Trying to wrap my head around it and find a more intuitive and comprehensive answer.
In my opinion talking about vectors as being "atomic" is more confusing than helpful. Instead, consider that R has a series of data types built into the language. They are given by definition and are distinct from one another.
For example, one such data type is "integer vector", which represents a sequence of integer values. Note that R does not have a data type of "integer". If we are talking about integer 5 in R, it is actually an integer vector of length 1.
Another built-in data type is NULL. There is a single object of type NULL, which is also called NULL. Since NULL is a type and an object, but not an integer value, it cannot be part of an integer vector.
Missing data in an integer vector are represented by NA. In this context NA is considered an integer value. Note that NA can also be a numeric value, logical value, etc. NA is a not a data type, but a value.
A complete list of built-in data types can be found in the R source code and also in the documentation, e.g. https://cran.r-project.org/doc/manuals/r-release/R-ints.html#SEXPTYPEs
I am trying to do some calculations where I divide two vectors. Sometimes I encounter a division by zero, which cannot take place. Instead of attempting this division, I would like to store an empty element in the output.
The question is: how do I do this? Can vectors have empty fields? Can a structure be the solution to my problem or what else should I use?
No, there must be something in the memory slot. Simply store a NaN or INT_MIN for integer values.