To save the output of a SPARQL query against the Virtuoso /sparql
endpoint to a file, a curl
command of the following form can be run:
curl --request POST 'http://hostname:portno/sparql/?' --header 'Accept-Encoding: gzip' --data 'format=outputformat' --data-urlencode 'query=SPARQLQuery' --output 'filename.gz'
The supported "outputformat" values, are detailed in the SPARQL Protocol Extensions section of the Virtuoso documentation.
The following example demonstrates how to save the output of a simple CONSTRUCT Query that returns the first 5 triples from the Quad store in JSON format:
$ curl --request POST 'http://localhost:8890/sparql/?' --header 'Accept-Encoding: gzip' --data 'format=json' --data-urlencode 'query=CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }LIMIT 5' --output 'filename.gz' % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 398 0 288 100 110 41854 15986 --:--:-- --:--:-- --:--:-- 48000 $ gzip -cd filename.gz | more { "head": { "link": [], "vars": [ "s", "p", "o" ] }, "results": { "distinct": false, "ordered": true, "bindings": [ { "s": { "type" : "uri", "value" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" } , "p": { "type" : "uri", "value" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" } , "o": { "type" : "uri", "value" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property" }}, { "s": { "type" : "uri", "value" : "http://www.openlinksw.com/virtrdf-data-formats#default-iid-nullable" } , "p": { "type" : "uri", "value" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" } , "o": { "type" : "uri", "value" : "http://www.openlinksw.com/schemas/virtrdf#QuadMapFormat" }}, { "s": { "type" : "uri", "value" : "http://www.openlinksw.com/virtrdf-data-formats#default-iid" } , "p": { "type" : "uri", "value" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" } , "o": { "type" : "uri", "value" : "http://www.openlinksw.com/schemas/virtrdf#QuadMapFormat" }}, { "s": { "type" : "uri", "value" : "http://www.openlinksw.com/virtrdf-data-formats#default-iid-nonblank-nullable" } , "p": { "type" : "uri", "value" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" } , "o": { "type" : "uri", "value" : "http://www.openlinksw.com/schemas/virtrdf#QuadMapFormat" }}, { "s": { "type" : "uri", "value" : "http://www.openlinksw.com/virtrdf-data-formats#default-iid-nonblank" } , "p": { "type" : "uri", "value" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" } , "o": { "type" : "uri", "value" : "http://www.openlinksw.com/schemas/virtrdf#QuadMapFormat" }} ] } } $