Re: isNumeric

On 19/09/10 21:13, Axel Polleres wrote:
> Hi all,
>
> Don't we need something like a function isNumeric to test for a numeric argument?
> Seems to be handy, useful for instance for numeric aggregates, or no?
>
> It seems COALESCE together with a cast would work as well, but
> something like
>    SUM(IF(isNumeric(?X), ?X, 0))
> looks better - at least to me - than:
>      SUM(COALESCE(xs:double(?X) , 0))
>
> Opinions?
>
> Axel

I believe we eventually agreed that sum() would skip any evaluation 
errors of the summation as being more consistent in style for SPARQL. It 
makes it more consistent since you can always do:

sum(?X+0)

to make the check happen before the aggregate is called. We do not 
define any situation that causes a runtime evaluation error in SPARQL 
(systems may issue warnings or reject the query, of course).

PREFIX ex: <http://example.org/>
PREFIX rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT ?T (Sum(?Pr) AS ?P)
WHERE { ?Item rdf:type ?T; ex:price ?Pr }
GROUP BY ?T

We may want isNumeric, but it's not required here.

	Andy

PS The data and queries have several syntax errors.

Received on Monday, 20 September 2010 08:27:02 UTC