Why is `datatype(?o)` empty in this query?

29 Views Asked by At

I was surprised to run this query

SELECT ?s, datatype(?s), ?p, datatype(?p), ?o, datatype(?o)
WHERE {
   ?s ?p ?o .
} 
LIMIT 100

and discover that the datatype(?o) column is blank. The first row of the result shows this:

?s           http://dbpedia.org/ontology/deathDate  
datatype(?s) http://www.w3.org/2001/XMLSchema#anyURI    
?p           http://www.w3.org/1999/02/22-rdf-syntax-ns#type    
datatype(?p) http://www.w3.org/2001/XMLSchema#anyURI    
?o           http://www.w3.org/2002/07/owl#FunctionalProperty
datatype(?o)

The definition of the datatype function in the SPARQL 1.1 spec doesn't shed any light into why datatype(?o) would be empty. I don't know whether this is expected behavior or whether it's a Virtuoso quirk.

1

There are 1 best solutions below

0
AndyS On

datatype(?s) evaluates to an error.

datatype takes a literal for an argument but ?p and ?s can't be literals and ?o isn't in the data shown.

As error in a assignment (BIND, or here project expression) leaves it unbound.

With legal SPARQL syntax:

SELECT (datatype(<http//example/>) AS ?dts ) {}

evaluates to

-------
| dts |
=======
|     |
-------