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/S01000309 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S01000309 geosparql: asWKT POLYGON ((-2.717731275984272 57.10215157620614, -2.717164747540609 57.10102291451913, -2.718488904275861 57.09950612511276, -2.717778728509349 57.098629825313786, -2.715806166259901 57.09819193783225, -2.716158710700159 57.09678851837164, -2.718422853755404 57.09609282338932, -2.718705465134744 57.09534558485713, -2.717446659714162 57.09340340381223, -2.717242267977928 57.0913653492132, -2.715234183141533 57.09048314318436, -2.711715689305947 57.087352933184434, -2.707334481344945 57.08772338193498, -2.707191721128043 57.08724514384999, -2.705672282529634 57.08691240015112, -2.706507466124931 57.08571290575857, -2.70625190372955 57.084420740075586, -2.703059857880964 57.07703638517699, -2.706478699590932 57.07118692884836, -2.706641147736837 57.070188857181286, -2.70507478816232 57.06847287040224, -2.705410527728029 57.06747993678085, -2.7068728965231 57.066764871810676, -2.705400873612605 57.06566821296668, -2.704152336098238 57.06570027538798, -2.703043725593599 57.06300844915313, -2.701866641550086 57.06290530010439, -2.701464338792758 57.061613308083615, -2.698856539956964 57.06141082842591, -2.696920974458221 57.05931051181956, -2.694721243803536 57.059825803068655, -2.692987253909478 57.05879333406251, -2.691001822054579 57.0593073741057, -2.690485415696211 57.05902275319295, -2.688802346552281 57.059840527466335, -2.687965965177246 57.05741062259088, -2.681736564226709 57.055755806454144, -2.687152319488881 57.05531297370208, -2.686012743035673 57.053414738964705, -2.690265112235515 57.052484047261004, -2.690885160298251 57.05302861809822, -2.69478060991325 57.05241416148949, -2.694198176806621 57.052120938654646, -2.695725030756229 57.05178906275833, -2.696290819654144 57.05207338765584, -2.698388642158305 57.051423883727615, -2.698724822079631 57.05089198583062, -2.701917802351939 57.05063157958712, -2.702878011801633 57.050850778713986, -2.702805102086737 57.05135425960843, -2.704161088399008 57.05158021068569, -2.704624006545987 57.05339225926176, -2.70795025700483 57.05492763288849, -2.707637555570222 57.05322255065146, -2.709225639401621 57.0526476106412, -2.710731945869377 57.05297145806502, -2.712041311135093 57.052478916253456, -2.711893458059536 57.051644296089016, -2.718740147135361 57.05364442961238, -2.719931094285912 57.05299976448629, -2.720892744391642 57.054135129789145, -2.722376353736809 57.053282139228045, -2.723757919237786 57.05396588645241, -2.72489406122184 57.05389643152082, -2.725895870087053 57.05454641903248, -2.725588987101657 57.05487160105157, -2.726381619575702 57.05493887392471, -2.726479654687574 57.05573783291795, -2.732245870988096 57.05386264577378, -2.733108729117977 57.05163868872106, -2.732685900101447 57.05025771136275, -2.727382300507793 57.04709950381462, -2.730147216998429 57.04269050420847, -2.73695192587864 57.04010832062808, -2.731858181944721 57.035835118568265, -2.743053189770123 57.03370297813908, -2.756500762426966 57.02978649416896, -2.758373520289261 57.0319491710344, -2.768225766311004 57.02874487643497, -2.766995716696563 57.028213407945294, -2.765072372365672 57.028413832161405, -2.770244950756551 57.02601046722919, -2.787210001020192 57.022787649729395, -2.802078841556724 57.021785925737966, -2.802444983754548 57.02425405275123, -2.801268919842955 57.0262469506177, -2.804172638509637 57.02568931903769, -2.805552775889208 57.02704594459339, -2.813373707736397 57.02761523958098, -2.815226334215255 57.02720791299934, -2.815209271856331 57.024171581777225, -2.816356512348764 57.022403328076734, -2.816149017817197 57.0129360026208, -2.817979977650829 57.01157651277859, -2.82490543587707 57.00977027749832, -2.835760906894537 57.00923111160394, -2.838366092253403 57.00500037830809, -2.840792089291321 57.00379826673401, -2.8433648605657 57.003268890105396, -2.84447079430248 56.99831145844413, -2.846463840852913 56.99546815091001, -2.844170478598483 56.99086606031539, -2.842868948074819 56.98498157125601, -2.840186770985667 56.984981644411455, -2.83749997630162 56.98331073600151, -2.831310931737103 56.98173496115317, -2.829939142590334 56.98071993622769, -2.83116405403673 56.97809756534329, -2.83360418773973 56.976859554562544, -2.837530174132607 56.97586309695091, -2.840167796223939 56.97391392374708, -2.850979357947124 56.97263702910978, -2.858162845195682 56.974564359014124, -2.861831234064679 56.97883333056197, -2.867313494588972 56.98040351907691, -2.874687079033894 56.98051388727874, -2.883509224657086 56.984817961412126, -2.88866463806154 56.98640749350948, -2.894823228662349 56.98657920638469, -2.903882589434565 56.9835404819997, -2.910196745883943 56.98268617019351, -2.912537595818309 56.9815192027755, -2.91042252289522 56.97575808487885, -2.916008733756654 56.9754657593661, -2.923988845881611 56.97219987703883, -2.944979912104411 56.97355232849749, -2.946205513245148 56.96933866430394, -2.947147737318502 56.96822652913601, -2.954955538355462 56.96674772571086, -2.967624765430712 56.96947126190833, -2.971280969133881 56.96964955205981, -2.973171936389594 56.96962587019378, -2.973548107631008 56.96891322335661, -2.988460274305513 56.96805060945586, -2.994139583564244 56.9682301946074, -2.99784382182298 56.97020408851939, -2.999411663056136 56.97039819995389, -3.000641106109477 56.96901384609376, -3.004166360334579 56.96737748935596, -3.009591196202421 56.967270931201256, -3.019706196080071 56.969668416924705, -3.026472057550991 56.97285624700695, -3.024222973578917 56.97601902519105, -3.024850295200907 56.976696659055676, -3.022113516341097 56.980087988465186, -3.022617840979728 56.98047915552301, -3.022145761898075 56.98126460755106, -3.014530658615652 56.98439905783886, -3.012528247228788 56.987011601087275, -3.016016404780916 56.98759422289125, -3.01069499997888 56.98858960692742, -3.011637342164537 56.99056741122673, -3.011046481520971 56.99487542813779, -3.001033627984324 57.00019347649302, -3.000489343972875 57.00199458446085, -3.00356187570538 57.0042159252968, -2.999558533158291 57.012710672343395, -2.987784057563265 57.022641340784986, -2.97774616147101 57.02553204930567, -2.974210650734569 57.030177237130175, -2.949754036393552 57.036348281907756, -2.933031531108813 57.037767654967055, -2.923688005248336 57.04108002288556, -2.922655177350343 57.05459003017952, -2.924452910473024 57.05793664594784, -2.928350190371185 57.05950690573629, -2.917013763239215 57.06248313290801, -2.916101469896242 57.06226521824832, -2.914169098746173 57.0628093689001, -2.911156856220305 57.06235518370818, -2.913040127384832 57.065854057037036, -2.911439302653651 57.06715036796521, -2.908650728383784 57.0677635415409, -2.897552982552082 57.07191310562301, -2.891076307900799 57.07144727449498, -2.881856806119925 57.072983784861805, -2.876019066307305 57.07577624695756, -2.873892234033996 57.077847816988786, -2.874911732819008 57.078385667588265, -2.879607842094656 57.07836972546069, -2.879176968572831 57.07921965489706, -2.880296393140866 57.07953441822595, -2.892213917488779 57.07660657618411, -2.892976487556068 57.07675708811036, -2.893986863838529 57.07646710017466, -2.893684031602446 57.07615858404065, -2.91344572367072 57.07028000886484, -2.91734320643103 57.069820317895626, -2.910898413016755 57.07267022202612, -2.91432377410259 57.07312140193352, -2.918457773300564 57.07487889547173, -2.91578771609299 57.078312201146176, -2.914545531647126 57.077440884654166, -2.905875948828525 57.078420189831554, -2.906455383108665 57.08391394031286, -2.90209171165831 57.08562535681233, -2.895091576487098 57.08613371615785, -2.896703703033536 57.087299035681866, -2.894161789207801 57.08932052735368, -2.894930630119696 57.09041103186253, -2.896605484750056 57.09074941897305, -2.898710477272371 57.0924951149236, -2.900243880640712 57.092439189617124, -2.901364703617682 57.09374273121852, -2.90191701383591 57.09541868059919, -2.900348189715436 57.096741556298745, -2.893011274467377 57.09774630358107, -2.890720813113759 57.09721460579111, -2.881650050959297 57.09889577599521, -2.879267811864366 57.09796924312641, -2.878864349782261 57.10881516360289, -2.874736052246642 57.109481868433484, -2.871552673650128 57.10891113072716, -2.869799016646728 57.10946232051714, -2.866133229767911 57.10873309009404, -2.863077293550432 57.10866433410652, -2.860441672564316 57.10464886772568, -2.854052235625513 57.10604907197196, -2.857278733703995 57.11065353743788, -2.85181680756742 57.11007091262681, -2.852291805067782 57.1120620131127, -2.846788213686627 57.11182980717748, -2.844433453681363 57.109932212263985, -2.838394593572314 57.11010749945315, -2.837343131043752 57.108874811299636, -2.826255685371788 57.10919992065486, -2.825794387720991 57.10850225068543, -2.823479770221525 57.10835577652265, -2.815811918983529 57.11027446996288, -2.815723060229479 57.10998757828851, -2.813831014060451 57.11179656277368, -2.812804511492482 57.11166847034533, -2.81359539217576 57.11234608061314, -2.811976713204335 57.11307524989651, -2.806546655538173 57.10786398242402, -2.804096555511943 57.106792729343574, -2.805088070870039 57.106076672948895, -2.804087181566448 57.10559799141396, -2.801943905877348 57.10572850856288, -2.80132234014271 57.104465818350754, -2.799781122229369 57.10418819222208, -2.790771275693118 57.10899758828212, -2.800476387031293 57.113463632339275, -2.792754066500644 57.11525548499631, -2.793719004790895 57.117135895771085, -2.789209196736286 57.116283992532715, -2.782846972819855 57.11606336439603, -2.777770896537368 57.11732568413546, -2.77090036529754 57.119667866449674, -2.763480554662843 57.11863526549406, -2.761464129640584 57.11935721561353, -2.756991887558476 57.116276050966796, -2.756582595191736 57.11078069402944, -2.758920573640189 57.11046112698763, -2.759054059927586 57.108915176337526, -2.765596730613983 57.10754584436933, -2.769044937742513 57.10584484042387, -2.768162252887955 57.104673426662266, -2.771778327906434 57.10074343305046, -2.757841112071926 57.09883416470275, -2.750030493062339 57.09865656545266, -2.751826888720582 57.096894039701915, -2.744282954720353 57.09517832347236, -2.734517587477712 57.09375368019934, -2.734190240253014 57.09472580423489, -2.726042147521767 57.09665080090355, -2.724055251929345 57.103094389446866, -2.726842218636484 57.10379692800679, -2.725365299547695 57.10593454059198, -2.718512607985669 57.1049948249864, -2.717731275984272 57.10215157620614), (-2.781458758797311 57.07696974488948, -2.784835342563768 57.07794933967373, -2.78691827248856 57.07763278377936, -2.79232404760437 57.07782330100926, -2.792215817877982 57.07689063886252, -2.794327170174685 57.07688625590967, -2.794405136502224 57.07729409411224, -2.795931908254608 57.07766619060708, -2.795536540292699 57.07860195585311, -2.797173906661679 57.078549180901774, -2.798462382652087 57.07716334384872, -2.805576892856605 57.07763192176541, -2.801832317603448 57.07065843426859, -2.800971089807642 57.069055283686964, -2.798099891040599 57.06951852441651, -2.796633493579199 57.069214121824544, -2.793750418731415 57.069628132083444, -2.79373860617042 57.070344019004914, -2.789487251509291 57.071913057163336, -2.788978554933937 57.07058803838184, -2.787503963656469 57.069716519136826, -2.781681590044968 57.07171046752777, -2.775984698103819 57.07229392719593, -2.770710998193109 57.07317985747089, -2.767240471150963 57.07285080723048, -2.76373252710051 57.070698247337106, -2.758982271276712 57.071490708611016, -2.752384517596658 57.07146762498695, -2.752236588233745 57.071864704349906, -2.752375384299603 57.072311465955224, -2.760133839394447 57.07311270633667, -2.761359932750266 57.074445600884964, -2.76095914448313 57.07579937925965, -2.762539249754856 57.07712375208046, -2.7621579164597 57.077952661570684, -2.763222524884579 57.079095855536956, -2.762353116506249 57.07945084306345, -2.762980820511216 57.082818382147956, -2.765734275477879 57.08254743416593, -2.766239980739228 57.08075083456247, -2.767965217048163 57.078845022099465, -2.770062868677902 57.08084894685244, -2.769585688665845 57.08299117222863, -2.771442451256161 57.0827173634077, -2.771003368361964 57.084509432064586, -2.772063531870555 57.0846837227733, -2.772920914590277 57.08128387685577, -2.774127271020903 57.08123533547747, -2.774298431959304 57.08050313723273, -2.776892435801688 57.08023236513236, -2.7766943199492 57.079245602344145, -2.779095494583402 57.07866689854337, -2.778109577329965 57.078004916549325, -2.779723774679931 57.077146659410886, -2.780723922743117 57.07738972539912, -2.781458758797311 57.07696974488948))
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>