Hello Renan,
According to SPARQL 1.0 spec, datatype() is a bit more peculiar than
just a function that returns "IRI after ^^", as it would be guessed from
its name:
-----8<-----
11.4.7 datatype
IRI datatype (typed literal typedLit)
IRI datatype (simple literal simpleLit)
Returns the datatype IRI of typedLit; returns xsd:string if the
parameter is a simple literal.
-----8<-----
After your first insert, it returns xsd:string as a datatype of a typed
literal.
After your second insert, it returns xsd:string because the parameter is
a simple (untyped) literal.
A tricky and undocumented way of returning different values for there
two values is
SQL> sparql select ?o (iri(sql:RDF_DATATYPE_OF_OBJ(?o, 'untyped!')))
from <teste_datatype> { <a> <string> ?o} ;
o callret-1
VARCHAR VARCHAR
_______________________________________________________________________________
string 2 untyped!
string 1 http://www.w3.org/2001/XMLSchema#string
The internal Virtuoso/PL function DB.DBA.RDF_DATATYPE_OF_OBJ, visible in
SPARQL as sql:RDF_DATATYPE_OF_OBJ, gets two arguments, first is used
like the first argument of standard DATATYPE(), second is the value to
be returned for untyped ltierals. Second argument can be omitted, in
this case its default value http://www.w3.org/2001/XMLSchema#string is
used.
More correctly, DATATYPE() works like sql:RDF_DATATYPE_OF_OBJ, not vice
versa, because SPARQL-to-SQL front-end of Virtuoso translates the SPARQL
call of DATATYPE() into SQL call of DB.DBA.RDF_DATATYPE_OF_OBJ :)
Best Regards,
Ivan Mikhailov
OpenLink Software
http://virtuoso.openlinksw.com
On Tue, 2011-07-26 at 19:30 -0300, Renan Moreira de Oliveira wrote:
> Hi,
>
> If I try to query after an object as string, and in the insert
> operation it was typecasted to xsd:string it doenst match. Is this the
> correct behavior ? We are confused because both typecasted and not
> typecasted points to xsd:string.
>
> See the example below:
>
> #Explicit typecast (insert)
> SQL> sparql insert into <teste_datatype> { <a> <string> "string
> 1"^^xsd:string . };
> callret-0
> VARCHAR
> _______________________________________________________________________________
>
>
> Insert into <teste_datatype>, 1 triples -- done
>
>
> 1 Rows. -- 14 msec.
>
> #Don't explicit typecast (insert)
>
> SQL> sparql insert into <teste_datatype> { <a> <string> "string 2". };
> callret-0
> VARCHAR
> _______________________________________________________________________________
>
>
> Insert into <teste_datatype>, 1 triples -- done
>
>
> 1 Rows. -- 5 msec.
>
> #Verify datatype query. Is equal datatype .
>
> SQL> sparql select ?o datatype(?o) from <teste_datatype> { <a>
> <string> ?o} ;
> o
> callret-1
> VARCHAR
> VARCHAR
> _______________________________________________________________________________
>
>
> string 1
> http://www.w3.org/2001/XMLSchema#string
> string 2
> http://www.w3.org/2001/XMLSchema#string
>
>
> 2 Rows. -- 4 msec.
>
> #The query to first insert. Return false.
>
> SQL> sparql ask from <teste_datatype> { <a> <string> "string 1" . };
>
> __ask_retval
> INTEGER
> _______________________________________________________________________________
>
>
>
>
> 0 Rows. -- 3 msec.
>
> #The query to second insert. Return true.
>
> SQL> sparql ask from <teste_datatype> { <a> <string> "string 2" . };
> __ask_retval
> INTEGER
> _______________________________________________________________________________
>
>
> 1
>
>
> 1 Rows. -- 14 msec.
>
>
>
> My virtuoso version:
> ./virtuoso-t -?
> Virtuoso Open Source Edition (multi threaded)
> Version 6.1.2.3127-pthreads as of Dec 16 2010
> Compiled for Linux (x86_64-unknown-linux-gnu)
> Copyright (C) 1998-2010 OpenLink Software
>
>
> Best regards,
> Renan Oliveira
> -----------------------------------------------
> Busca & Semântica - Globo.com
> (21) 2483-6727
> Y! glb_renan
> ------------------------------------------------------------------------------
> Got Input? Slashdot Needs You.
> Take our quick survey online. Come on, we don't ask for help often.
> Plus, you'll get a chance to win $100 to spend on ThinkGeek.
> http://p.sf.net/sfu/slashdot-survey
> _______________________________________________ Virtuoso-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/virtuoso-users