SPARQL Functions Reference¶
What’s in this document?
This section lists all supported SPARQL functions in GraphDB. The function specifications include the types of the arguments and the output. Types from XML Schema should be readily recognizable as they start with the xsd:
prefix. In addition, the following more generic types are used:
rdfTerm
Any RDF value: a literal, a blank node or an IRI.
iri
An IRI.
bnode
A blank node.
literal
A literal regardless of its datatype or the presence of a language tag.
string
A plain literal or a literal with a language tag. Note that plain literals have the implicit datatype
xsd:string
.numeric
A literal with a numeric XSD datatype, e.g.
xsd:double
andxsd:long
.variable
A SPARQL variable.
expression
A SPARQL expression that may use any constants and variables to compute a value.
SPARQL 1.1 Functions¶
Function |
Description |
---|---|
|
Returns |
|
The IF function form evaluates the first argument, interprets it as a effective boolean value, then returns the value of e2 if the EBV is true, otherwise it returns the value of e3. Only one of e2 and e3 is evaluated. If evaluating the first argument raises an error, then an error is raised for the evaluation of the IF expression. More |
|
The COALESCE function form returns the RDF term value of the first expression that evaluates without error. In SPARQL, evaluating an unbound variable raises an error. If none of the arguments evaluates to an RDF term, an error is raised. If no expressions are evaluated without error, an error is raised. More |
xsd:boolean NOT EXISTS { pattern } xsd:boolean EXISTS { pattern } |
There is a filter operator EXISTS that takes a graph pattern. EXISTS returns |
|
Returns a logical OR of left and right. Note that logical-or operates on the effective boolean value of its arguments. More |
|
Returns a logical AND of left and right. Note that logical-and operates on the effective boolean value of its arguments. More |
|
Returns |
|
Returns |
|
The IN operator tests whether the RDF term on the left-hand side is found in the values of list of expressions on the right-hand side. The test is done with |
|
The NOT IN operator tests whether the RDF term on the left-hand side is not found in the values of list of expressions on the right-hand side. The test is done with |
xsd:boolean isIRI(rdfTerm term) xsd:boolean isURI(rdfTerm term) |
Returns |
|
Returns |
|
Returns |
|
Returns |
xsd:string STR(literal ltrl) xsd:string STR(iri rsrc) |
Returns the lexical form of ltrl (a literal); returns the codepoint representation of rsrc (an IRI). This is useful for examining parts of an IRI, for instance, the hostname. More |
|
Returns the language tag of the literal ltrl, if it has one. It returns “” if ltrl has no language tag. Note that the RDF data model does not include literals with an empty language tag. More |
|
Returns the datatype IRI of the literal ltrl. More |
iri IRI(string str) iri IRI(iri rsrc) iri URI(string str) iri URI(iri rsrc) |
The IRI function constructs an IRI by resolving the string argument str. The IRI is resolved against the base IRI of the query and must result in an absolute IRI. If the function is passed an IRI rsrc, it returns the IRI unchanged. More |
bnode BNODE() bnode BNODE(string str) |
The BNODE function constructs a blank node that is distinct from all blank nodes in the dataset being queried and distinct from all blank nodes created by calls to this constructor for other query solutions. If the no argument form is used, every call results in a distinct blank node. If the form with the string str is used, every call results in distinct blank nodes for different strings, and the same blank node for calls with the same string within expressions for one solution mapping. More |
|
Return a fresh IRI from the UUID URN scheme. Each call of UUID() returns a different UUID. More |
|
Return a string that is the scheme specific part of UUID. That is, as a string literal, the result of generating a UUID, converting to a string literal and removing the initial |
|
The STRLEN function corresponds to the XPath |
string SUBSTR(string source, xsd:integer startingLoc) string SUBSTR(string source, xsd:integer startingLoc, xsd:integer length) |
The SUBSTR function corresponds to the XPath |
|
The UCASE function corresponds to the XPath |
|
The LCASE function corresponds to the XPath |
|
The STRSTARTS function corresponds to the XPath |
|
The STRENDS function corresponds to the XPath |
|
The CONTAINS function corresponds to the XPath |
|
The STRBEFORE function corresponds to the XPath |
|
The STRAFTER function corresponds to the XPath |
|
The ENCODE_FOR_URI function corresponds to the XPath |
|
The CONCAT function corresponds to the XPath The lexical form of the returned literal is obtained by concatenating the lexical forms of its inputs. If all input literals are literals with identical language tag, then the returned literal is a literal with the same language tag, in all other cases, the returned literal is a simple literal. More |
|
Returns |
xsd:boolean REGEX(string text, xsd:string pattern) xsd:boolean REGEX(string text, xsd:string pattern, xsd:string flags) |
Invokes the XPath |
string REPLACE(string arg, xsd:string pattern, xsd:string replacement) string REPLACE(string arg, xsd:string pattern, xsd:string replacement, xsd:string flags) |
The |
|
Returns the absolute value of num. An error is raised if the argument is not a numeric value.
|
|
Returns the number with no fractional part that is closest to num. If there are two such numbers, then the one that is closest to positive infinity is returned. An error is raised if the argument is not a numeric value.
|
|
Returns the smallest (closest to negative infinity) number with no fractional part that is not less than the value of num. An error is raised if the argument is not a numeric value.
|
|
Returns the largest (closest to positive infinity) number with no fractional part that is not greater than the value of num. An error is raised if the argument is not a numeric value.
|
|
Returns a pseudo-random number between 0 (inclusive) and 1.0 (exclusive). Different numbers can be produced every time this function is invoked. Numbers should be produced with approximately equal probability. More |
|
Returns an XSD dateTime value for the current query execution. All calls to this function in any one query execution will return the same value. The exact moment returned is not specified. More |
|
Returns the year part of arg as an integer.
|
|
Returns the month part of arg as an integer.
|
|
Returns the day part of arg as an integer.
|
|
Returns the hours part of arg as an integer. The value is as given in the lexical form of the XSD dateTime.
|
|
Returns the minutes part of the lexical form of arg. The value is as given in the lexical form of the XSD dateTime.
|
|
Returns the seconds part of the lexical form of arg.
|
|
Returns the timezone part of arg as an xsd:dayTimeDuration. Raises an error if there is no timezone.
|
|
Returns the timezone part of |
xsd:string MD5(xsd:string arg) |
Returns the MD5 checksum, as a hex digit string, calculated on the UTF-8 representation of the lexical form of the argument. More |
xsd:string SHA1(xsd:string arg) |
Returns the SHA1 checksum, as a hex digit string, calculated on the UTF-8 representation of the lexical form of the argument. More |
xsd:string SHA256(xsd:string arg) |
Returns the SHA256 checksum, as a hex digit string, calculated on the UTF-8 representation of the lexical form of the argument. More |
xsd:string SHA512(xsd:string arg) |
Returns the SHA512 checksum, as a hex digit string, calculated on the UTF-8 representation of the lexical form of the argument. More |
SPARQL 1.1 Constructor Functions¶
Casting in SPARQL 1.1 is performed by calling a constructor function for the target type on an operand of the source type. The standard includes the following constructor functions:
Note
Note that SPARQL 1.1 does not have an xsd:date
constructor. Instead, use STRDT(value,xsd:date)
to attach the xsd:date
datatype to the value.
Constructor function |
Description |
---|---|
|
The STRDT function constructs a literal with lexical form and type as specified by the arguments. More |
|
The STRLANG function constructs a literal with lexical form and language tag as specified by the arguments. More |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |
|
Casts value to |