Is there some way to use a kind of placeholder variable with SPARQL without returning it when using SELECT * ? (kleene star)

For example:

   ?s dcterms:title ?title; 
      foaf:person ?name. 
   ?s2 :inProject ?s. 

Where I would not want to return the ?s variable, just the ?title, ?name, and ?s2 variables while leaving the SELECT *.

I understand I can limit the select results by using SELECT ?title ?name ..., but I'm just curious if there is some kind of notation for placeholder variables or some way to manage this.

EDIT: - I understand you can use blank nodes to accomplish this in some cases, for example:

   _:s dcterms:title ?title; 
      foaf:person ?name. 
   ?s2 :inProject _:s. 

However, doesn't this cause problems since blank nodes can't be used across basic graph patterns? For example, this breaks in the case:

   _:s dcterms:title ?title; 
      foaf:person ?name. 
   OPTIONAL{ ?s2 :inProject _:s. }


asked 21 Feb '13, 11:24

Dev-Deverton's gravatar image

accept rate: 0%

edited 21 Feb '13, 13:48

 WHERE{ _:s dcterms:title ?title ; foaf:person ?name. ?s2 :inProject _:s }

_:s serves as a non-distinguished variable that will not be returned as a solution to the query.

permanent link

answered 21 Feb '13, 11:39

Signified's gravatar image

Signified ♦
accept rate: 37%

edited 21 Feb '13, 11:41


Doesn't this cause a problem with scope when using multiple graph patterns? You can't use this in a query such as: SELECT * WHERE { _:s dcterms:title ?title ; foaf:person ?name. OPTIONAL{?s2 :inProject _:s}}, correct? Supposedly blank nodes can't be used across basic graph patterns...

(21 Feb '13, 13:40) Dev-Deverton Dev-Deverton's gravatar image

Duplicating my answer from SO:

For variables scoped to a single pattern yes, use the blank node variable syntax as you demonstrated by @Signified's answer and in your question

In the general case no, if you use a variable then SELECT * will return it.

One possible workaround is to use sub-queries where you do list variables and leave out the variables you don't want e.g.

    SELECT ?title ?name ?s2 WHERE 
      ?s dcterms:title ?title; 
      foaf:person ?name. 
      OPTIONAL{ ?s2 :inProject ?s. }

But then I assume this is exactly what you are trying to avoid since you end up listing variables anyway.

permanent link

answered 21 Feb '13, 18:00

Rob%20Vesse's gravatar image

Rob Vesse ♦
accept rate: 29%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 21 Feb '13, 11:24

question was seen: 627 times

last updated: 21 Feb '13, 18:00