Blake Regalia
Blake Regalia

Reputation: 2766

SPARQL Select Variable Prefix "?" and "$"

According to the specification, there is absolutely no difference between using the "?" and "$" variable prefix characters, even when mixing and matching. For example, this is totally legal:

SELECT  $title
WHERE   { <book1>  dc:title  ?title }

The SPARQL docs even have this to add:

A query variable is marked by the use of either "?" or "$"; the "?" or "$" is not part of the variable name. In a query, $abc and ?abc identify the same variable

Does anybody know why they created two redundant ways to prefix a variable? I didn't even know about the "$" until today while skimming the syntax's production rules. Using "?" is so common now, seems like "$" is just a lexical waste of a character.

Upvotes: 2

Views: 321

Answers (1)

Jeen Broekstra
Jeen Broekstra

Reputation: 22052

The original drafts of SPARQL started with just using '?' (which IIRC was taken from one of SPARQL's predecessor languages, RDQL). One reason the use of '$' was introduced was that at the time, the W3C SPARQL Working Group foresaw the use of existing ODBC/SQL tooling to handle SPARQL queries. Since '?' is a character with a distinct reserved meaning in SQL, it was felt an alternative or synonym should be allowed to better facilitate carrying SPARQL queries over ODBC connections. See this mailing list discussion for further details

As for why the Working Group standardised on allowing both (rather than just replacing the use of '?' outright): a vote was taken, several members objected to taking out the '?' completely (presumably because not everyone was convinced about the ODBC argument), so both were kept as a compromise.

Upvotes: 5

Related Questions