Update Functions
This topic describes the SPARQL functions that are used to load, insert, or update data.
- CLEAR: Deletes all of the triples in a graph without deleting the graph.
- COPY: Copies graph data from the database to disk.
- CREATE: Creates a new empty graph.
- DELETE and DELETE DATA: Deletes the specified graph or triple patterns or specific triples from the database.
- DROP: Deletes a graph and all of its triples.
- INSERT and INSERT DATA: Inserts the specified graph or triple patterns or specific triples to the database.
- LOAD: Loads data to the database from RDF files that are on the AnzoGraph DB file system. For information, see Load RDF Data from Files.
Typographical Conventions
The following list describes the conventions used to document function syntax:
CAPS
: Although SPARQL is case-insensitive, SPARQL keywords in this section are written in uppercase for readability.[ argument ]
: Brackets indicate an optional argument or keyword.|
: Means OR. Indicates that you can use one or more of the specified options.
CLEAR
The CLEAR function deletes all of the triples in a graph without deleting the graph.
Syntax
CLEAR [ SILENT ] GRAPH <graph_URI> | DEFAULT | NAMED | ALL
The optional SILENT keyword tells AnzoGraph DB not to return an error if an error occurs.
Statement | Description |
---|---|
CLEAR GRAPH <graph_URI> | Deletes all of the triples from the named graph. |
CLEAR DEFAULT | Deletes all of the triples from the default graph. |
CLEAR NAMED | Deletes all of the triples from all of the named graphs in the database. |
CLEAR ALL | Deletes all of the triples from all graphs. |
COPY
In AnzoGraph DB, the COPY operation is used to copy graph data from the database to files on disk. For information on using the AnzoGraph DB COPY command, see Copy Graphs to Files.
CREATE
The CREATE function creates a new empty graph.
Syntax
CREATE [ SILENT ] GRAPH <graph_uri>
The optional SILENT keyword tells AnzoGraph DB not to return an error if an error occurs.
DELETE and DELETE DATA
The DELETE function deletes the specified graph or triple patterns from the database. The DELETE DATA function deletes specific triples from the database. DELETE DATA statements cannot include variables.
DELETE Syntax
Use the following syntax to delete graph and triple patterns with the DELETE function.
DELETE { graph_and_triple_patterns } WHERE { graph_and_triple_patterns }
DELETE DATA Syntax
Use the following syntax to delete specific triples with the DELETE DATA function.
DELETE DATA { [ GRAPH <graph_uri> { ] triples } [ } ]
The optional GRAPH statement specifies the graph to delete the triples from. The triples that you list must include URIs, literal, values, or blank nodes. You cannot specify triple patterns with variables. For example, the query below uses DELETE DATA to remove the person0 triples from the tickit graph:
DELETE { GRAPH <http://anzograph.com/tickit> { <person0> <http://anzograph.com/tickit/firstname> "Jay" . <person0> <http://anzograph.com/tickit/lastname> "Stevens" . <person0> <http://anzograph.com/tickit/state> "CA" . } }
DROP
The DROP function deletes a graph and all of its triples.
Syntax
Use the following syntax to delete graphs and their triples using the DROP function.
DROP [ SILENT ] GRAPH <graph_uri> | DEFAULT | NAMED | ALL
The optional SILENT keyword tells AnzoGraph DB not to return an error if an error occurs.
Option | Description |
---|---|
DROP GRAPH <graph_URI> | Deletes the named graph. |
DROP DEFAULT | Since a graph database must always have a default graph, the DROP DEFAULT operation deletes the triples from the default graph; it does not remove the graph. DROP DEFAULT is synonymous with CLEAR DEFAULT. |
DROP NAMED | Deletes all of the named graphs in the database. |
DROP ALL | Deletes all of the graphs and their triples from the database. Since the default graph cannot be removed, the triples from the default graph are deleted but the default graph remains. |
INSERT and INSERT DATA
The INSERT function inserts the specified graph or triple patterns into the database. The INSERT DATA function inserts specific triples into the database. INSERT DATA statements cannot include variables.
INSERT Syntax
Use the following syntax to insert data using graph and triple patterns. The syntax below inserts triples into the default graph:
INSERT { triple_patterns } WHERE { triple_patterns }
The following syntax inserts triples into a named graph. The WHERE clause specifies the named graph to find triple patterns.
INSERT { GRAPH <graph_uri> { triple_patterns } } WHERE { GRAPH <graph_uri> { triple_patterns } }
As an alternative, you can include one or more USING clauses to specify named graphs for the WHERE clause. USING acts like a FROM clause in a SELECT query.
INSERT { GRAPH <graph_uri> { triple_patterns } } USING <graph_uri> WHERE { triple_patterns }
INSERT DATA Syntax
Use the following syntax to insert specific triples with the INSERT DATA function.
INSERT DATA { triples }
Use the following syntax to insert specific triples into a graph with the INSERT DATA function.
INSERT DATA { GRAPH <graph_uri> { triples } }
The GRAPH statement specifies the graph to insert the triples in. The triples that you list must include URIs, literal, values, or blank nodes. You cannot specify triple patterns with variables. For example, the query below uses INSERT DATA to add a new user to the sample tickit data set:
INSERT DATA { GRAPH <http://anzograph.com/tickit> { <person0> <http://anzograph.com/tickit/firstname> "Jay" . <person0> <http://anzograph.com/tickit/lastname> "Stevens" . <person0> <http://anzograph.com/tickit/state> "CA" . } }
The query below inserts a graph named "friends" using data from the tickit graph.
INSERT { GRAPH <friends> { ?person <http://anzograph.com/tickit/friendOf> ?friend . } USING <http://anzograph.com/tickit> WHERE { ?person <http://anzograph.com/tickit/friend> ?friend . }