add cart choropleth column cross cube error file folder geo help home lock obs poi rdf remove search slice spreadsheet success table unlock warning

[this is a icon-] developer tool

SPARQL 1.1 Query: Results

Edit query
Query results
s p_blank o_blank
http://statistics.gov.scot/id/statistical-geography/S02000194 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S02000194 geosparql: asWKT POLYGON ((-3.5481615984394 55.261928555928876, -3.542663855562561 55.26340912467388, -3.537498937352486 55.26333051113558, -3.535446522182008 55.26397643860194, -3.529838132327886 55.26423559461198, -3.529815268858073 55.26527835786987, -3.525653644927097 55.2659235934388, -3.522089483706424 55.26737903085909, -3.518005144167904 55.267996066177396, -3.508162636464699 55.275325531253074, -3.507318854558108 55.276737902704625, -3.498731279791167 55.28154374774791, -3.490593323104538 55.28285660670872, -3.488403356095775 55.28239804388507, -3.481225529937641 55.27525996921337, -3.479312971682241 55.26658393413597, -3.473845387269674 55.2668388055259, -3.47662461530533 55.25775549949111, -3.470949369266167 55.257042184351825, -3.468531537338842 55.25548063539786, -3.469601562454212 55.253778230946345, -3.469330293246079 55.251543781991565, -3.471434040117647 55.24972107306495, -3.470403889979606 55.248664058555484, -3.463269260843246 55.24886665080877, -3.462445753659157 55.24786101936414, -3.458169807797915 55.248370513538894, -3.456465845195053 55.24694399453051, -3.455142834903633 55.24819097008113, -3.452897857243768 55.24831657456725, -3.452729150723334 55.24886677505697, -3.448694954354807 55.246946631990234, -3.448246236797753 55.24628693245692, -3.428915070706294 55.247206831809535, -3.422634364132227 55.24797219792756, -3.422220078366831 55.24738390243621, -3.423968316915908 55.24612333685334, -3.423168648232306 55.24575522891428, -3.42045648413237 55.245571144954525, -3.419767821325154 55.24610937761928, -3.41830327165765 55.24606350174105, -3.417197682351893 55.24682225069475, -3.416562467894311 55.24576919397718, -3.414093080791594 55.24489017405578, -3.412636014190362 55.24328044889526, -3.411230643598059 55.243125960856524, -3.410398976598733 55.24407020314062, -3.410978612528207 55.238231102696005, -3.41332311307447 55.233387058915504, -3.415016629738239 55.22660937735143, -3.416174366355964 55.21811239256075, -3.41246611319289 55.21941357002153, -3.412925511342762 55.22096056649954, -3.407125517179497 55.221181183814394, -3.406175602945404 55.2233505631487, -3.403526720988951 55.22491780453513, -3.402155783346618 55.22706342944319, -3.399920648543599 55.227439584346556, -3.396113832330601 55.22918171268385, -3.395453693217435 55.228290584071615, -3.395694414901383 55.22663427321845, -3.40072689350513 55.22130136565803, -3.401424641389788 55.21968471761951, -3.393132898160128 55.22037282713735, -3.390979716822508 55.217683399929676, -3.386870091589275 55.2165798927922, -3.379763862693414 55.21699299701779, -3.375644567480846 55.217875288986896, -3.376073040694724 55.22163589919982, -3.369318136450648 55.224983083321206, -3.364694629993007 55.22448670920662, -3.360537035372009 55.22658211778521, -3.360064718811444 55.23117060164063, -3.360626213893286 55.23149685005034, -3.358747097661715 55.23587633082281, -3.359232416080325 55.23673364678966, -3.355243876521707 55.238296765349126, -3.358574226640124 55.24003010468901, -3.36183412247495 55.242914435978726, -3.355618757251916 55.24469111757905, -3.344668717884542 55.245090864589535, -3.338534197063022 55.246497325614826, -3.333636259891345 55.24679359491019, -3.329218264402279 55.24780337865196, -3.331774590133926 55.24051429526547, -3.333636459043846 55.23881345674616, -3.333628185020464 55.23433819468755, -3.340030430912707 55.228786174716156, -3.340596286902538 55.225976110542646, -3.341049034019806 55.22074088917291, -3.338581469707396 55.21747886555486, -3.339167494267786 55.215270692352085, -3.340307537164052 55.21458416983079, -3.340466185553876 55.21369274009118, -3.338050356347867 55.20446297201612, -3.338475838571418 55.197942936962306, -3.346606336773401 55.197709635530465, -3.348146570766434 55.19540100580445, -3.348727417015752 55.19259970790989, -3.347691466221591 55.19169451008037, -3.342791883419607 55.192206891415154, -3.341338757082516 55.19197125431479, -3.338804938369107 55.190426429434005, -3.335120508325764 55.19298310564955, -3.333293698769139 55.19190672074755, -3.332944830339259 55.192278990314925, -3.329940723517728 55.19216800601482, -3.325427506843256 55.19013222724775, -3.324840544711359 55.18853897400697, -3.312548744522121 55.18782721894333, -3.306777994284012 55.18356618855586, -3.30122958934789 55.18235453738292, -3.295799252399237 55.18053188020336, -3.295469308402329 55.17964059498731, -3.296568406167403 55.17890362591999, -3.296526513697773 55.176163126550684, -3.294919641296894 55.17261249221026, -3.295053805763747 55.17093953788818, -3.291836898687044 55.17002108734556, -3.285002280642427 55.16449461309298, -3.288829966403863 55.162468143152736, -3.293027228831751 55.16314262550952, -3.293664987797349 55.16053869503999, -3.295431324232912 55.1598279602437, -3.298196087736041 55.15989739557972, -3.298271120240996 55.15834189776184, -3.299622405288311 55.157905124028716, -3.302622358354118 55.158933527892756, -3.303324876596661 55.159779752756975, -3.302824327832727 55.16127690542623, -3.30734374991331 55.16219908256688, -3.30899907406225 55.16050079015205, -3.312886774851643 55.16130372985118, -3.313200082538389 55.160329784660526, -3.332076933509911 55.15968459224709, -3.337010500207396 55.1584263489826, -3.340752523800029 55.1581515821044, -3.341193665372468 55.1577333359758, -3.339526577866568 55.15388735508063, -3.339863191972862 55.14988454122753, -3.343191896628891 55.14387168177027, -3.342106373312277 55.1437847894399, -3.341862672364827 55.14306852971389, -3.338938875416724 55.1429029765259, -3.338136031632557 55.14235461267041, -3.337314904336833 55.14360380762026, -3.331597295330731 55.14434941963283, -3.328466448634838 55.141732491307664, -3.326689578883854 55.142084362677366, -3.329263839000213 55.132683086393655, -3.317244495958498 55.13445820569257, -3.316319066151757 55.13350662299169, -3.311520091808801 55.133055111176034, -3.310461316100426 55.13090069709022, -3.309895674625492 55.130870825491705, -3.309192088310384 55.13141759685612, -3.305432246709329 55.13155679254583, -3.303915536754004 55.133145722798304, -3.302398194224724 55.13375507695611, -3.303092310189398 55.13195029777642, -3.299244157436684 55.13226998891731, -3.298995460809433 55.13137396764511, -3.296981540503095 55.13166501743522, -3.295234938815833 55.13052431192955, -3.293463474909063 55.1305521127987, -3.292896420897997 55.13144782260771, -3.290215510416841 55.13148523233534, -3.290161719781826 55.13273495874725, -3.285009799111368 55.13349037010269, -3.283040819422496 55.13323252609957, -3.282295292313843 55.131505939923784, -3.282740522758989 55.12876029309939, -3.28414467458737 55.128529823825076, -3.285670334698664 55.125736827586415, -3.287663909418717 55.12384652814937, -3.289226374481565 55.12026226261122, -3.288433346199538 55.117547658256086, -3.288886694622184 55.115071498824335, -3.287402434801815 55.11474570116506, -3.283501346942227 55.11581135770186, -3.277742456966187 55.11369710804616, -3.279012389067838 55.1107540990086, -3.278547686954404 55.104549119432534, -3.27755394559265 55.10287902287004, -3.284754448398717 55.09867834765572, -3.288049780606424 55.09344916440304, -3.292176210321206 55.09506801623326, -3.293310202024395 55.09475940948314, -3.295726275872081 55.097268008808385, -3.297216605001006 55.09731505170747, -3.297957390555494 55.09841253380747, -3.298901467396834 55.09852828455597, -3.300337802480947 55.09980705676163, -3.300213133585774 55.100311644306245, -3.302590108712897 55.10111303325976, -3.304055605161873 55.09894949774253, -3.305983929270053 55.09848848599844, -3.30616739290496 55.09882801374924, -3.309413533095992 55.09793042074266, -3.310005712911161 55.097348895820474, -3.311104096999493 55.09739100202112, -3.315122261968626 55.0932856229416, -3.317577447026908 55.09265697189378, -3.318452878652113 55.0935461786297, -3.31956624623966 55.09357006402149, -3.318961539839303 55.09376534040702, -3.320184961592852 55.095225922805646, -3.322627828451797 55.09517246155536, -3.325297828135341 55.09582642661023, -3.327072894738332 55.09558609717294, -3.329310099863768 55.096312918377826, -3.330197326572204 55.09513651498758, -3.328558190247866 55.09441873063024, -3.330544676394707 55.09337871746126, -3.330143819390702 55.092160880383496, -3.331379912823414 55.091635122523684, -3.331054383183679 55.090326601298564, -3.331942923575918 55.08830382946832, -3.337577502361733 55.085779666207365, -3.338960515354787 55.08590825598579, -3.339247170475503 55.08651620808196, -3.340009792060667 55.08636402800617, -3.340150935106353 55.087773410806314, -3.344639012995912 55.0870499192482, -3.345228474929493 55.08780729491726, -3.34902862615974 55.08759449909801, -3.34997061182045 55.08672131858712, -3.351415021076123 55.086345826356116, -3.351617617960463 55.08724226361551, -3.359727185451836 55.08659478833232, -3.360567531409083 55.087349289592105, -3.37821895039142 55.08716875269546, -3.373734743422195 55.092557648881964, -3.370920461294796 55.09228381030294, -3.369819727424183 55.094462044791946, -3.363340632989645 55.095172821760066, -3.362588022967449 55.09377928845162, -3.358916473291908 55.09364057892695, -3.357778306684613 55.097508644200325, -3.362641818057799 55.0972026883032, -3.36400253878778 55.09988352293689, -3.363634949485555 55.10335657456778, -3.366180711597044 55.10125207353603, -3.380140236726525 55.10246069390293, -3.379392447412561 55.10350265279684, -3.379733667157984 55.10430761221098, -3.383044817027509 55.1057798517958, -3.385209736399232 55.10537780520779, -3.386537712716821 55.107061215820266, -3.384306701916089 55.11326059604501, -3.38215856211484 55.11370737029275, -3.380412062156533 55.11534481191019, -3.381015057454843 55.11555366672205, -3.379141832229207 55.118522581764275, -3.377345419807727 55.11826431804069, -3.372781020304324 55.11913364468966, -3.372424436739762 55.118337831295435, -3.362153721013671 55.120169597944034, -3.363899648528866 55.12584773020458, -3.368997099171441 55.12677911063553, -3.370946227421092 55.12553497565404, -3.372665119417148 55.12535385786194, -3.377388213968492 55.12588470015582, -3.37784635143732 55.12643670609833, -3.381191587010183 55.12702790359394, -3.383731379504803 55.12473438840552, -3.385714300079348 55.12402885408848, -3.386961845227023 55.12653996915337, -3.390222660247175 55.126502802514615, -3.39638524029396 55.11749035965932, -3.398760457887211 55.11860444191002, -3.399885508218942 55.118492664030825, -3.404283634227223 55.11558420183714, -3.405476428200187 55.116064726239095, -3.403422734455299 55.11830817273468, -3.400837763379092 55.123298701476386, -3.401035783001061 55.12492305472094, -3.401954142958761 55.12517310714627, -3.406656610767369 55.12466056525214, -3.409538319330679 55.12499572063186, -3.40922683574146 55.12550259547869, -3.405294251274058 55.125610930557386, -3.405491834764704 55.12721730025532, -3.407522215972154 55.127867885395474, -3.410049763958602 55.1279375121255, -3.414292731848734 55.12728620470842, -3.414274280235211 55.1280952436093, -3.412135393464578 55.129261387831356, -3.411997358391598 55.13068291957259, -3.416188675843353 55.13343818291206, -3.41677947312792 55.134617593096486, -3.415845126207461 55.13879837615956, -3.410938557194002 55.14112897129515, -3.408564515951682 55.14410413972916, -3.40955559760155 55.14462290371363, -3.408001127711465 55.145036290366974, -3.408638585888911 55.146206206966625, -3.412502969375721 55.14544252432756, -3.414428733734387 55.14621103723778, -3.41196457895446 55.15063419791481, -3.406752820311447 55.15593381437336, -3.40677211179499 55.15648178664452, -3.410492260423591 55.15916180544741, -3.409165114307307 55.16158563700812, -3.407416893320323 55.16275615396978, -3.407577418913173 55.16330249559594, -3.412742456538016 55.16420434069783, -3.414213013240463 55.162731416649, -3.416275229802221 55.162896187704334, -3.418115221919387 55.165202395381996, -3.418061559757704 55.16634434682873, -3.420309416134119 55.166426019898, -3.42071592654469 55.16505528317876, -3.423789938823572 55.164534116778285, -3.425538544258137 55.16734455159348, -3.429998126506903 55.169125630321815, -3.431361180468848 55.167615118026326, -3.432574342385744 55.16816018878516, -3.433950206959658 55.16779598763098, -3.43836507220707 55.16805470525374, -3.438316774088053 55.169124218616666, -3.43929389121154 55.16913754996975, -3.438499315355871 55.17178198462148, -3.441902422488364 55.170692988290654, -3.441693837068825 55.17475744234924, -3.44384305780311 55.17513642177138, -3.451148422847277 55.16919021633728, -3.453545900737311 55.16992553974767, -3.456996701365743 55.171987273156006, -3.460700196452517 55.17536697006229, -3.459485847693498 55.17823036079411, -3.461881760056933 55.180619127138975, -3.464766998890469 55.18221112710297, -3.46551643086068 55.18380178869521, -3.466572360195912 55.18432830822032, -3.466704238701199 55.18749011123269, -3.469717056328161 55.18740889433057, -3.476695186070708 55.191764111910075, -3.480551054634911 55.19322715821358, -3.477167155528801 55.20196751494301, -3.474908951621661 55.20293847083271, -3.475116994692006 55.208139365327526, -3.477211073113426 55.20909358537632, -3.479791185382665 55.2138253545797, -3.480822022146751 55.21449584895635, -3.480527486582836 55.21502964883045, -3.481289264849633 55.21564948652315, -3.480581756460743 55.21776100131185, -3.48378202603123 55.21800969222808, -3.486221403044261 55.21724306918719, -3.486450689647582 55.21664714147014, -3.490007835675492 55.21635210362086, -3.491241231498044 55.21738849821982, -3.493470859716683 55.21816105068322, -3.493543640691298 55.22178187992095, -3.501882134088816 55.22654140440055, -3.504677437593639 55.22895139273526, -3.511009736954937 55.22925057583296, -3.512880626497013 55.23007215800082, -3.514981909477456 55.229920262917965, -3.520389237860706 55.230697761100615, -3.528514418539792 55.232222852074806, -3.531698664068492 55.233243376725575, -3.535643036334503 55.233580226099434, -3.535210298384468 55.23745005484163, -3.536506788152379 55.238035860579636, -3.5361971222669 55.238569987152374, -3.537064843341049 55.238639939695226, -3.537554001986843 55.23949652132157, -3.537249132576831 55.243823069945904, -3.53782242263374 55.24522679880669, -3.539933112130078 55.24814788354012, -3.545501638396206 55.249353624672636, -3.545798906352415 55.25052714930676, -3.543204286346272 55.25339985047208, -3.5481615984394 55.261928555928876))
SPARQL API: The Basics

The most flexible way to access the data is by using SPARQL, a query language, analagous to SQL for relational databases, for retrieving and manipulating data from graph databases like ours. We support SPARQL 1.1 query syntax. Many online tutorials are available.

To submit a SPARQL query from your code, you issue an HTTP GET or POST to our endpoint:http://statistics.gov.scot/sparql, with the query itself as a url-encoded parameter called query.

For example, to run the following simple SPARQL query and get the results as JSON:

SELECT * WHERE {?s ?p ?o} LIMIT 10

Option 1: POST (recommended)

Issue a POST to the endpoint, with the query in the body, and an Accept header of sparql-results+json:

POST http://statistics.gov.scot/sparql HTTP/1.1
Host: statistics.gov.scot
Accept: application/sparql-results+json
Content-Type: application/x-www-form-urlencoded

query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

Option 2: GET

Issue a GET to the following URL (note the .json extension - see the formats section for more detail on this):

GET http://statistics.gov.scot/sparql.json?query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

Scroll down to the end of this page for examples of both of these methods in a few different languages.

Results formats

As with other aspects of our API, to get the data in different formats, you can use either (a) a format extension or (b) an HTTP Accept header. Available result formats depend on the type of SPARQL query. There are four main forms:

SELECT queries return tabular results, and the formats available reflect this:

Format Extensions Accept Headers
XML .xml application/xml,
application/sparql-results+xml
JSON .json application/json,
application/sparql-results+json
Text .txt, .text text/plain
CSV .csv text/csv

CONSTRUCT and DESCRIBE queries return graph data, so the results are available in the same formats as our resource APIs:

Format Extensions Accept Headers
RDF/XML .rdf application/rdf+xml
N-triples .nt, .txt, .text application/n-triples,
text/plain
Turtle .ttl text/turtle
JSON-LD .json application/ld+json,
application/json

ASK queries return a boolean result:

Format Extensions Accept Headers
XML .xml application/xml,
application/sparql-results+xml
JSON .json application/json,
application/sparql-results+json
Text .txt, .text text/plain
Results pagination

We accept page and per_page parameters for paginating the results of SELECT queries (we automatically modify your query to apply LIMIT and OFFSET clauses). For other query types (i.e. DESCRIBE, CONSTRUCT, ASK), pagination like this doesn’t make so much sense, so these parameters are ignored.

For requests made through the website (i.e. HTML format), the page size is defaulted to 20. For requests to our sparql endpoint for data formats (i.e. non-HTML), there will be no defaults for these parameters (i.e. results are unlimited. For performance reasons we generally advise LIMITing your query if possible).

Parameter Substitution

You can parameterise your SPARQL by including %{tokens} in your queries, and providing values for the tokens in the request parameters.

Note that the following tokens are reserved and cannot be used as parameters for substitution:

  • controller
  • action
  • page
  • per_page
  • id
  • commit
  • utf8
  • query
Cross Origin Resource Sharing

Our servers are configured to allow access from all domains. This means that if you’re writing JavaScript to request data from our server in to a web page hosted on another domain, your browser should check this header and allow it.

If you need to support very old browsers, you can additionally pass a callback parameter and the results will be wrapped in that function. For example:

http://statistics.gov.scot/sparql.json?callback=myCallbackFunction&query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

This help topic on the jQuery website has more details.

Examples

Using cURL

Here’s a couple of examples running a query using the widely available cURL command line program.

Request the results as XML, using a POST:

curl -X POST -H "Accept: application/sparql-results+xml" -d "query=SELECT%20*%20WHERE%20%7B%3Fs%20%3Fp%20%3Fo%7D%20LIMIT%2010" http://statistics.gov.scot/sparql

Request the results as JSON, using a GET:

curl -X GET -H "Accept: application/sparql-results+json" http://statistics.gov.scot/sparql?query=SELECT%20*%20WHERE%20%7B%3Fs%20%3Fp%20%3Fo%7D%20LIMIT%2010

Using JavaScript

This example HTML page uses jQuery to issue a POST to our SPARQL endpoint, requesting the results as JSON.

<!DOCTYPE html>
<html lang='en'>
<head>
	<script src='http://code.jquery.com/jquery-1.9.1.min.js'></script>
</head>
<body>
<script type='text/javascript'>

	var query = 'SELECT * WHERE {?s ?p ?o} LIMIT 10';
	var url = 'http://statistics.gov.scot/sparql.json';
	$.ajax({
		method: 'POST',
		dataType: 'json',
		url: url,
		data: {query: query},
		success: function(data) {
			alert('success: ' + data.results.bindings.length + ' results');
			console.log(data);
		}
	});
</script>
</body>
</html>