How can I obtain the object datatype?

To display the object datatype of a triple in a SPARQL result set, the internal Virtuoso/PL function DB.DBA.RDF_DATATYPE_OF_OBJ can be used, invoked as sql:RDF_DATATYPE_OF_OBJ.

Assume the following scenario:


# Explicit typecast (insert) 
SQL> sparql insert into <test_datatype> { <a> <string> "string 1"^^xsd:string . };
callret-0
VARCHAR
_______________________________________________________________________________

Insert into <test_datatype>, 1 (or less) triples -- done

1 Rows. -- 94 msec.


#Not explicit typecast (insert)
SQL> sparql insert into <test_datatype> { <a> <string> "string 2". };
callret-0
VARCHAR
_______________________________________________________________________________

Insert into <test_datatype>, 1 (or less) triples -- done

1 Rows. -- 16 msec.

SQL> SPARQL 
SELECT ?o (iri(sql:RDF_DATATYPE_OF_OBJ(?o, 'untyped!'))) 
FROM <test_datatype> { <a> <string> ?o} ;
o                       callret-1
VARCHAR                 VARCHAR
_______________________________________________________________________________

string 1                http://www.w3.org/2001/XMLSchema#string 
string 2                untyped!

2 Rows. -- 16 msec.
SQL>	

Related