0

Hi I have a SPARQL query that has has this in the where clause

...
optional {
        ?v foo:thing ?something .
        $dontgetthis
        ?v bar:somethingelse ?otherthing .
...
}
...

Now, I get most of this, except one thing. I don't get $dontgetthis. What does this mean? $dontgetthis is not used anywhere else in the query.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304

1 Answers1

5

The dollar sign is a legal variable prefix in SPARQL, so you can use variables like $v, but that doesn't appear to be what's happening. You can have an optional as the only thing within a WHERE, so a query like this is legal:

prefix foo: <>
prefix bar: <>
select * where { 
  optional {
          ?v foo:thing ?something .
          ?v bar:somethingelse ?otherthing .
  }
}

I'd rather wonder whether the query you're seeing with$dontgetthis inside is a string where $dontgetthis is going to be replaced by something else by some other code. It's not legal SPARQL by itself.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • Does that mean that a variable can be prefixed with either a dollar or a question mark? Is there any difference between these two? – Sachin Kainth Jan 23 '15 at 13:24
  • 1
    The only difference is that one begins with a question mark, and the other begins with a dollar sign. `$foo` and `?foo` are the same variable. The (freely available online, so this isn't secret information or anything) spec *explicitly* says so: *"**[4.1.3 Syntax for Query Variables](http://www.w3.org/TR/sparql11-query/#QSynVariables)** 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."* – Joshua Taylor Jan 23 '15 at 13:34
  • 1
    @JoshuaTaylor But isn't `$` customarily used for query params, i.e. vars that will be bound from the outside when the query is executed? – Vladimir Alexiev Jan 13 '17 at 19:12
  • @VladimirAlexiev Some people might have that convention. I've never seen it before, though. – Joshua Taylor Jan 13 '17 at 19:14
  • @JoshuaTaylor Yeah, the sesame (rdf4j) people: http://docs.rdf4j.org/rest-api/#_repository_queries and search for `$` – Vladimir Alexiev Jan 25 '17 at 07:12