Notice: Scheduled maintenance is set for Tuesday, Sept 2nd at 1am EST. During this time, we will experience up to 20 minutes of downtime. Thank you for your patience.

Hi all,

Given a dataset with URIs of the format, I want to use a Sparql PREFIX to shorten the queries. When I run on Virtuoso:

PREFIX mysite:<>
select * where { mysite:a:something/b:somethingelse ?p ?o }

I get the error 37000 Error SP030: SPARQL compiler, line 2: Undefined namespace prefix at '' before '?p'

Clearly, the problem is the character : in the query. What is the best solution in this case? Should I remove all the : from the URIs to make them usable in SPARQL?

Thanks for any hint,


asked 12 Nov '12, 07:45

mulone's gravatar image

accept rate: 0%

In SPARQL 1.1 you can write:

PREFIX mysite:<>
select * where { mysite:a:something\/b:somethingelse ?p ?o }

Note in front of the /. Multiple colons are allowed in prefixed names, only the first separates the prefix from the local part. These changes were in a later last call draft, and are in the final publication, to align SPARQL and the standardisation of Turtle, which is work-in-progress by the RDF working group. Virtuoso coverage will vary.

The SPARQL validator at is up to date with these changes.


answered 12 Nov '12, 08:51

AndyS's gravatar image

AndyS ♦
accept rate: 32%

You can escape such characters using a backslash:

PREFIX mysite:<>
select * where { mysite:a\:something\/b\:somethingelse ?p ?o }

If for some reason your SPARQL engine does not accept this (escaping chars like this is a SPARQL 1.1 feature, not all engines will have implemented it), you can either choose to just use the entire URI in the query for such cases:

PREFIX mysite:<>
select * where { <> ?p ?o }

...or you can of course modify your data (if it's your own data to edit) so that you don't use such chars in URIs.


answered 12 Nov '12, 08:54

Jeen%20Broekstra's gravatar image

Jeen Broekstra ♦
accept rate: 37%

edited 12 Nov '12, 08:55

The final decision was that : is used as-is in the local part of a prefixed name and isn't escaped (due to tracking changing Turtle).

(12 Nov '12, 09:02) AndyS ♦ AndyS's gravatar image
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



Asked: 12 Nov '12, 07:45

Seen: 1,357 times

Last updated: 12 Nov '12, 09:08