SPARQL/Extensions/Selecting Expressions
SQL allows for arbitrary expressions to be projected out of a query. These expressions can be simple values from source data or functions on both source data and constant values. The SPARQL specification does not allow this, but it is a commonly requested feature.
- ARQ supports expressions in the
SELECT
clause. - Virtuoso supports arbitrary expressions enclosed in parentheses in a
SELECT
clause. - SPARQLplus is a Sesame 2 drop-in replacement for the standard SPARQL engine that supports use of function calls and aliases in the
SELECT
clause. - Glitter, part of Open Anzo, supports arbitrary expressions in the
SELECT
clause. These expressions must be parenthesized and must use theAS
keyword to name the result of the expression.
There is a bit of a discussion of approaches to selecting arbitrary expressions in both SELECT
clauses and CONSTRUCT
templates in the comments of Andy Seaborne's post on aggregates in ARQ. An article on RAP's new SPARQL engine contains a section (4.3) showing examples of arbitrary expressions in a SELECT
clause.
Note that some implementations support selecting expressions limited to a particular set of aggregate functions. These implementation approaches are discussed on the SPARQL aggregates page.