How to validate datetime object in SPARQL? (Virtuo

2019-06-28 03:56发布

I get the following error.

Virtuoso 22007 Error DT006: Cannot convert -0359 to datetime : Incorrect month field length

SPARQL query:
define sql:big-data-const 0 
#output-format:text/html
define sql:signal-void-variables 1 select ?item  bif:year(xsd:dateTime( str(?dob))) as ?m{
?item <h://f.cm/ns/common/topic/notable_types> <h://f.cm/ns/people/person> .
?item <h://f.cm/ns/people/person/date_of_birth> ?dob 
} limit 675

If I change the limit to 674, it works.

What I suspected was that some datetime field is wrong somewhere and printed ?dob, which revealed that one of the values is -0359.

Solution is to validate the value before applying bif function.

But, how can we validate datetime in SPARQL?

1条回答
Fickle 薄情
2楼-- · 2019-06-28 04:14

Well, I found this question via Google because I had the same problem. Looking elsewhere for help, I found the following solution:

SELECT * {

  ?s ?p ?o

  FILTER ( datatype(?o) = xsd:datetime )
  FILTER ( coalesce(xsd:datetime(str(?o)), '!') != '!')

}

This worked for me.

Note that I found the answer to this at SemanticWeb.

查看更多
登录 后发表回答