Loading TOC...


   $sparql as xs:string,
   [$bindings as map:map?],
   [$options as xs:string*],
   [$store as sem:store*],
   [$default-permissions as element(sec:permission)*]
) as empty-sequence()


Executes a SPARQL Update operation against the database.

Graph Update - addition and removal of triples from some graphs within the Graph Store.

Graph Management - creating and deletion of graphs within the Graph Store, as well as convenient shortcuts for graph update operations often used during graph management (to add, move, and copy graphs).

This function is a built-in.

sparql The SPARQL Update to be executed.
bindings A map containing initial values for variables from the query, or the empty sequence if no query variables are to be initially bound. This is a way to parameterize the query.
options Options as a sequence of string values. Available options are:
The initial base IRI for the query.
Add the named graph or graphs specified by the IRI to the default graph for the query.
Add the named graph or graphs specified by the IRI to the list of named graphs available in the query.
Parse the query, but don't perform static checks or execute it.
Parse and optimize the query, caching the result. No execution is performed.
Sets the optimization level to use. Levels of 0 (off), 1, and 2 are recognized, with 1 as the default.
Sets de-duplication of triples results to "on" or "off". The default, standards-compliant behavior is "on".
Sets The database directory path of triples document. Default location is /triplestore.
The number of triples in a triples document. Default is 100.
Update fails if the specified destination graph does not already exist.
ISOLATION_LEVEL can be different-transaction or same-statement. Default is different-transaction, which will not change the transaction mode of the calling transaction. If isolation is same-statement, the calling transaction should be run in update mode and the $sparql cannot contain multiple statements.
TXN_ID is the transaction ID which the SPARQL program is in. Setting transaction-id implies isolation to be different-transaction. Transaction-id cannot coexist with isolation same-statement.
store A sem:store constructor to use as the source of the triples for SPARQL Update. If multiple sem:store constructors are supplied, the triples from all the sources are merged and queried together. The default for sem:store the current database's triple index. The locking option specified in sem:store will be used by sem:sparql-update.

If a sem:store value is not supplied, then the default sem:store for the statement will be used. This is the same as calling sem:store() with all arguments omitted, which will access the current database's triple index, using the default rulesets configured for that database. The default for locking is read-write.

Note: You cannot use an in-memory store with SPARQL Update.

$default-permissions Security permission elements corresponding to the permissions for the graph during graph creation. If not supplied, the current user's default permissions are applied. The default value used for this parameter can be obtained by calling xdmp:default-permissions(). A RDF graph that is created by a non-admin user (that is, by any user who does not have the admin role) must have at least one update permission, otherwise the creation will throw an XDMP-MUSTHAVEUPDATE exception. Parameter is ignored if the operation does not involve graph creation.

Required Privileges

Requires the sparql-update-user role, or the following privileges:




Usage Notes

You cannot use an in-memory store with SPARQL Update.

The options parse-check and prepare cannot be used at the same time.


xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics"
      at "/MarkLogic/semantics.xqy";

(: Insert a triple into default graph and three triples into graph <BOOKS>. :)
PREFIX dc: <http://marklogic.com/dc/elements/1.1/>
   <http://example/book0> dc:title "A default book"
  GRAPH <BOOKS> {<http://example/book1> dc:title "A new book" }
  GRAPH <BOOKS> {<http://example/book2> dc:title "A second book" }
  GRAPH <BOOKS> {<http://example/book3> dc:title "A third book" }

(: Update any book title which is "A new book" to be "Insert MarkLogic Server". :)

PREFIX dc: <http://marklogic.com/dc/elements/1.1/>
DELETE {?b dc:title "A new book" }
INSERT {?b dc:title "Inside MarkLogic Server" }
  ?b dc:title "A new book" .

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.