-->

sparql expecting one of “where”, “using”

2019-03-02 17:40发布

问题:

I am trying to do a simple insert query in the web interface of Fuseki server. I have set the endpoint to /update (instead of the default /sparql). I have the following query from https://www.w3.org/Submission/SPARQL-Update/:

PREFIX dc: <http://purl.org/dc/elements/1.1/>
INSERT { <http://example/egbook3> dc:title  "This is an example title" }

This query gets translated to: http://localhost:3033/dataset.html#query=PREFIX+dc%3A+%3Chttp%3A%2F%2Fpurl.org%2Fdc%2Felements%2F1.1%2F%3E%0AINSERT+%7B+%3Chttp%3A%2F%2Fexample%2Fegbook3%3E+dc%3Atitle++%22This+is+an+example+title%22+%7D%0A or curl http://localhost:3033/infUpdate/update -X POST --data 'update=PREFIX+dc%3A+%3Chttp%3A%2F%2Fpurl.org%2Fdc%2Felements%2F1.1%2F%3E%0AINSERT+%7B+%3Chttp%3A%2F%2Fexample%2Fegbook3%3E+dc%3Atitle++%22This+is+an+example+title%22+%7D%0A' -H 'Accept: text/plain,*/*;q=0.9' as visible using the Share your query button.

The query returns the following error:

Error 400: Encountered "<EOF>" at line 2, column 73.
Was expecting one of:
    "where" ...
    "using" ...



Fuseki - version 2.4.0 (Build date: 2016-05-10T11:59:39+0000)

The error occurs both in the web interface and with curl. What could be the problem here? SELECT queries work without problems. Loading triples from a file through the web interface upload form also works. Additional question: the normal post request uses query= and the curl version uses update=, why is this different?

回答1:

The document you're referencing is the 2008 SPARQL Update submission, not the actual 2013 SPARQL 1.1 recommendation. The recommendation is the actual standard, the submission is not.

An update (insert or delete) isn't a query (select, ask, construct), and the syntax for the two kinds of query aren't necessarily the same. You note (correctly) that WHERE is optional in a select query, but that doesn't mean that it's optional in an insert. There are two forms of insert. There's INSERT DATA which has the syntax:

INSERT DATA  QuadData  

and there's DELETE/INSERT which has the syntax:

( WITH IRIref )?
( ( DeleteClause InsertClause? ) | InsertClause )
( USING ( NAMED )? IRIref )*
WHERE GroupGraphPattern

DeleteClause ::= DELETE  QuadPattern 
InsertClause ::= INSERT  QuadPattern 

So if you're using INSERT { … }, then that's the InsertClause of a DELETE/INSERT form, and you need to follow it with WHERE …. Since you're using static data, you should probably just use the INSERT DATA form:

PREFIX dc: <http://purl.org/dc/elements/1.1/>
INSERT DATA { <http://example/egbook3> dc:title  "This is an example title" }