Loading TOC...

sem:sparql-update

sem:sparql-update(
   $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()

Summary

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.

Parameters
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:
"base=IRI"
The initial base IRI for the query.
"default-graph=IRI*"
Add the named graph or graphs specified by the IRI to the default graph for the query.
"named-graph=IRI*"
Add the named graph or graphs specified by the IRI to the list of named graphs available in the query.
"parse-check"
Parse the query, but don't perform static checks or execute it.
"prepare"
Parse and optimize the query, caching the result. No execution is performed.
"optimize=N"
Sets the optimization level to use. Levels of 0 (off), 1, and 2 are recognized, with 1 as the default.
"dedup=N"
Sets de-duplication of triples results to "on" or "off". The default, standards-compliant behavior is "on".
"directory=URI"
Sets The database directory path of triples document. Default location is /triplestore.
"triples-document-size=xs:nonNegativeInteger"
The number of triples in a triples document. Default is 100.
"existing-graph"
Update fails if the specified destination graph does not already exist.
"isolation=ISOLATION_LEVEL"
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.
"transaction-id=TXN_ID"
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:

http://marklogic.com/xdmp/privileges/sem-sparql-update

http://marklogic.com/xdmp/privileges/any-uri

http://marklogic.com/xdmp/privileges/unprotected-collections

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.

Example

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>. :)
sem:sparql-update('
PREFIX dc: <http://marklogic.com/dc/elements/1.1/>
INSERT DATA
{
   <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". :)

sem:sparql-update('
PREFIX dc: <http://marklogic.com/dc/elements/1.1/>
WITH <BOOKS>
DELETE {?b dc:title "A new book" }
INSERT {?b dc:title "Inside MarkLogic Server" }
WHERE {
  ?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.