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/S01005147 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S01005147 geosparql: asWKT POLYGON ((-3.802487880371223 56.937115882766065, -3.78869729330974 56.92509425190699, -3.780828506309293 56.92547617376972, -3.764778599989457 56.931813664773294, -3.752362632524737 56.934441255382495, -3.740920507215966 56.935077341720884, -3.727363430157105 56.928014547895195, -3.725902800564683 56.920226777820986, -3.716284849961542 56.91828370750376, -3.707129561178105 56.91745670021582, -3.708457746658966 56.9148868221927, -3.699125675419506 56.91593052374461, -3.69509598812295 56.91762948949583, -3.690791622838008 56.91616934843957, -3.684167087788309 56.91607012007921, -3.677059000501794 56.92240122744433, -3.678426531541155 56.9272436955061, -3.672745414439231 56.93284554935586, -3.664229220776198 56.93166540415667, -3.656261364450003 56.93394556602495, -3.653047770847926 56.93151727506657, -3.649773713411469 56.92473205916215, -3.646984508649215 56.9233312720798, -3.635846589637853 56.926370658961524, -3.63310462850598 56.924537676496996, -3.60330051683201 56.931446478449594, -3.579520097805197 56.93180314470724, -3.576205830418254 56.927253799020775, -3.574124656435912 56.917244113464434, -3.556894433857503 56.89834951074156, -3.562709534371138 56.89488068681439, -3.56875918908821 56.89507440844114, -3.564927723152818 56.888644473893876, -3.560171980784207 56.8848135743776, -3.550532539459611 56.8854816709988, -3.549268217242846 56.88586573091418, -3.543891927722343 56.89002033477698, -3.538287070246298 56.89303645555594, -3.533622952275682 56.89058707521257, -3.530870121238531 56.884286644834944, -3.526414242931254 56.885697860368566, -3.520834485778196 56.88854218035953, -3.515415563516652 56.88646070410823, -3.511348515810456 56.88979835700465, -3.500097540083022 56.88757999850876, -3.497982154179635 56.88147786958556, -3.493582725618422 56.8826805858468, -3.489520063403079 56.87997980686293, -3.486192155196504 56.87551815838174, -3.476362164160529 56.87381985338528, -3.469498060156342 56.87534732711824, -3.464509818129269 56.87282734425441, -3.459821859319242 56.87504751176017, -3.455734222483998 56.8741518444874, -3.453958711636103 56.87702063352765, -3.446940898497135 56.87545795817233, -3.444682520572616 56.87773922453748, -3.447215364855679 56.88128575253393, -3.443957093142061 56.87977812053531, -3.440063747895747 56.88137739514298, -3.438583666350524 56.88599452984836, -3.429101899994145 56.886552590448055, -3.426753930358899 56.883084456900306, -3.416772632349999 56.879101135713235, -3.411119955800165 56.880638583151935, -3.405250421001244 56.88428057924831, -3.396791263451177 56.88145550511971, -3.393414510324807 56.87935491990641, -3.387327334598729 56.880707456083634, -3.380743991402114 56.87929796937298, -3.377787153371816 56.875647000531664, -3.372539518662037 56.87483328786812, -3.377227365115059 56.86845662782252, -3.376588020063962 56.86221947904346, -3.38065644912124 56.85734091548791, -3.388515816922606 56.851243137268206, -3.397744817094176 56.851167108476524, -3.405836835173154 56.84351127896188, -3.398775224900371 56.84362654288133, -3.391513414436483 56.84232408594844, -3.385800705051366 56.83767975362953, -3.380378468397606 56.83732654717694, -3.380179114499977 56.83591818458259, -3.376280192544059 56.830615456864905, -3.366989619337507 56.83201132533016, -3.365185484111245 56.829272833723095, -3.361308412216792 56.827203828033944, -3.35222576159703 56.823448227230365, -3.351394114071519 56.819009917504644, -3.362798303357923 56.81498661892928, -3.366617434156847 56.812797550383564, -3.362480328453803 56.808934531241384, -3.356144603724561 56.80765588125133, -3.360117179029051 56.79886171647206, -3.365621105815768 56.79531558665265, -3.366056395165915 56.79197755584418, -3.372177074934775 56.789673220217765, -3.37719578016616 56.785907282289664, -3.377168586662708 56.77801912696527, -3.388022455414515 56.77013609893934, -3.388458604108701 56.76776829117676, -3.384623691110554 56.76181820176567, -3.377152866373248 56.75391363108319, -3.371223538850449 56.75277505470132, -3.366534873411871 56.75336561609286, -3.362543206588472 56.75198075854035, -3.357445997033193 56.74895465419545, -3.356991612010125 56.744970442961296, -3.363340623375292 56.738782643005386, -3.347875664683985 56.729669763761, -3.351770826782043 56.72662671260841, -3.348045415173202 56.72436701035804, -3.338079231774346 56.71983837742807, -3.332541897303874 56.71250339754329, -3.331776965383476 56.710274408824155, -3.332245909654967 56.706441952735524, -3.340931202295686 56.701721682264974, -3.337166791696523 56.69136693073983, -3.32622078460766 56.68375719107467, -3.333243279873848 56.68199309164428, -3.344358090497309 56.68240369076583, -3.360933249868757 56.68076812670949, -3.364742445429027 56.68363747743715, -3.372773615913646 56.68496878666119, -3.376217759064168 56.68450849048625, -3.387064403280153 56.68780234254422, -3.390857127402756 56.68351026775277, -3.39259105892564 56.68404794185211, -3.400053330639045 56.68189777884299, -3.405874336944918 56.687851977877294, -3.40595627948701 56.689612062745496, -3.408620788757192 56.69319382240814, -3.407964778803465 56.6939918973556, -3.409126592118914 56.694931139821044, -3.408520871119977 56.695764587356834, -3.409909800730512 56.69840835535499, -3.411594877968067 56.6991276958939, -3.415767249934985 56.70285302024809, -3.413113585109162 56.70815819620438, -3.415678817717974 56.70982541630306, -3.425718635327364 56.71309816865764, -3.429449655889126 56.716703221167734, -3.44203290820293 56.72145491121252, -3.446990189657215 56.716078457970355, -3.479315837679679 56.71501598249819, -3.479416863033284 56.71426005764548, -3.486316732941448 56.71563347457908, -3.488157181820501 56.715485717765254, -3.487218771247556 56.716961449566064, -3.489726051249361 56.71838703964488, -3.491791627495862 56.716906779827326, -3.496626611763785 56.71933759822627, -3.498297598897721 56.71821237772375, -3.497860731394136 56.717498842565185, -3.498846044427562 56.716390840042294, -3.501377981370847 56.715965020421976, -3.501749881727255 56.715457386063385, -3.50131011417779 56.71467201855358, -3.49982952519109 56.71400700233191, -3.498401870733985 56.71179593657512, -3.492458943547479 56.7106543211706, -3.491961013470547 56.70674288963167, -3.492814190109237 56.70560057538688, -3.490684553245481 56.70337986534144, -3.502240566116009 56.701947213378375, -3.504422619015233 56.7005551758647, -3.502274641588549 56.69665470495391, -3.501312670063823 56.69669325962248, -3.499768105168303 56.69563368199838, -3.499599947830633 56.6930480599904, -3.50069406535951 56.69017768708931, -3.506546293047521 56.69116724753641, -3.5214075849961 56.689207571326094, -3.527525351757801 56.69069606096764, -3.527531950866226 56.69126203093664, -3.529473103391795 56.69201989730376, -3.531745939072716 56.691695459423826, -3.53278840933491 56.69082906574718, -3.53762978676364 56.6902302883655, -3.54375848591464 56.69037010757522, -3.545528878179911 56.68894649459831, -3.54656814358285 56.68880780213033, -3.549533606444126 56.68945379756597, -3.554695670663396 56.68951525255346, -3.559236818488226 56.68838027964067, -3.566259633146228 56.6892176053569, -3.565117621194828 56.690813322908056, -3.566448566476234 56.691407569360024, -3.573603859508073 56.69070638409303, -3.574584175849497 56.68993925213647, -3.577956522447315 56.69366129186965, -3.577250253018621 56.69434411435763, -3.578076087024453 56.69456726266444, -3.581964526286528 56.70006169084599, -3.584083476872777 56.70034923411232, -3.58450120905274 56.702904652414325, -3.587545503174995 56.70344093091966, -3.594502886040924 56.69956037882762, -3.610304631590592 56.70817142888203, -3.61306574306515 56.705889441686566, -3.634816846253642 56.70309004656243, -3.647220888811105 56.702495342367015, -3.648953076266676 56.70139420740947, -3.661992560548224 56.70226317718775, -3.669293089807315 56.70667610178162, -3.674723365396614 56.7042580836695, -3.678647687845 56.70838336593352, -3.678946335986046 56.71215311376676, -3.676583998626395 56.715239885170234, -3.677808105982235 56.71631061205241, -3.675019404317572 56.7175341779288, -3.677283585395025 56.718842504890894, -3.677694524407179 56.72036444703095, -3.67530127040353 56.7231371235045, -3.669437245385686 56.72652236213004, -3.67928534884786 56.730388419035215, -3.678666404150036 56.73520380989484, -3.686858811830226 56.73853449737889, -3.667016598350184 56.747526029804334, -3.658917093769281 56.748532600358644, -3.661129810736381 56.75383128672207, -3.660671558198681 56.75604772403819, -3.669755354022131 56.76207218435241, -3.672247350076425 56.76292830740934, -3.67212991376266 56.766541887138146, -3.695821920313994 56.77634812503656, -3.705652594075455 56.77839743232891, -3.708004752549331 56.78189639515113, -3.712833671957457 56.78226145103719, -3.714137134946515 56.78392376299042, -3.71934739949873 56.78367233671729, -3.725918251509917 56.784533999406534, -3.732784729914997 56.78044038019935, -3.736427338712759 56.77709214674222, -3.739622575222017 56.77505289836927, -3.748014741986827 56.776741563216845, -3.753255255414576 56.77576048285378, -3.766883777826873 56.777760515698, -3.773889953096954 56.7760526835416, -3.781362875873848 56.77591919339958, -3.787861908752952 56.7742357831627, -3.788768922221072 56.77231789160956, -3.795315092370643 56.7661587183149, -3.802212420123122 56.768053950323115, -3.806986163161268 56.765244323470725, -3.815667105723709 56.76510023145854, -3.821542542792948 56.76142037529253, -3.82750598174573 56.762941481969634, -3.833886371354944 56.76595673490284, -3.834418614288035 56.76546369409294, -3.834901522828815 56.765636295627196, -3.837038187956271 56.76486612581341, -3.836622686633707 56.76553905524715, -3.835865996627945 56.765514460816796, -3.836117031369978 56.76601755313736, -3.83677914727979 56.76625201700757, -3.837348856239477 56.765159965552265, -3.838340705724038 56.765702441125256, -3.83801524202901 56.76640809956309, -3.840057764153058 56.76681200539092, -3.841707539541811 56.765293333753554, -3.846483102600015 56.76391980864686, -3.84664353714106 56.763522073618034, -3.847220158470766 56.76360338442231, -3.847688418188422 56.76514193859825, -3.853322419330606 56.76558845377505, -3.852521654007359 56.764279495219, -3.858961798909051 56.76580999634413, -3.876168989078752 56.765372523636245, -3.880508308937291 56.76544192853417, -3.891388112998515 56.7693298102381, -3.896010755419941 56.770140176526404, -3.902172437751535 56.76934545241809, -3.906819873589292 56.76709097266568, -3.913778597273389 56.76718202997083, -3.918382883922423 56.77019331414264, -3.922463946183938 56.770319151794574, -3.927315932219899 56.76728798294566, -3.937447031968669 56.76543267349542, -3.942266801320344 56.766247254022346, -3.941580315667778 56.76942986879951, -3.93939600929173 56.77022764196979, -3.954953978735237 56.771404392940575, -3.962712337484251 56.77613475347398, -3.962879621086764 56.77871100152809, -3.960735434081924 56.783102772068176, -3.962852046413501 56.78852375607916, -3.962098552892144 56.79353162368419, -3.960278013556608 56.795042878742635, -3.951383803091128 56.800034575082606, -3.950759418510276 56.809766746367146, -3.947610130015155 56.812529597318274, -3.943484860056209 56.81480437569586, -3.941664135414938 56.821095656420155, -3.930054749089796 56.83177085768498, -3.928167092277721 56.82980525407963, -3.920849703437224 56.833179835176686, -3.921014099119875 56.83510918455445, -3.923433289871127 56.841047272868856, -3.920647545953055 56.844594505113136, -3.91982748889167 56.848111455708356, -3.915738217321761 56.85184034734193, -3.923408870997659 56.86741100667012, -3.928270451466406 56.86974412686707, -3.93280078491218 56.87327725645175, -3.935231399965069 56.88030218666757, -3.941156686293887 56.8841099220303, -3.945386150461676 56.88842902551084, -3.939915728843259 56.896268553701844, -3.941640273308044 56.89912609004154, -3.945165073640333 56.898702852337685, -3.948451675474631 56.90190437259193, -3.950955849703717 56.90552237264178, -3.955950096777813 56.90586660177048, -3.961879510387995 56.90493798394636, -3.965821780501381 56.905576882886635, -3.962432503522527 56.909529865026904, -3.964277307281295 56.9130681128762, -3.967402089015734 56.91594821949243, -3.966475862162777 56.92488537523361, -3.969446900208353 56.92856756133639, -3.964591421647086 56.93186077175485, -3.967442681682179 56.935446048619376, -3.964240181566824 56.93830886032004, -3.960073030652433 56.93564269975029, -3.953743701375262 56.93876089402496, -3.955675460219387 56.94143530094798, -3.95441894414492 56.94601055765917, -3.948472003958292 56.94736134271103, -3.944662223258306 56.94650415470775, -3.93791251078264 56.94950225637111, -3.939006202066932 56.94554970138411, -3.938294931603765 56.93976515986282, -3.935680139104636 56.93435154768675, -3.927112480130059 56.93330684947453, -3.92132601060172 56.93360259422026, -3.912502973079888 56.93012579822077, -3.908460518722099 56.93302695456448, -3.900072681744903 56.93161825687535, -3.901419345668041 56.92707815911189, -3.897734988899715 56.922803232674944, -3.891650145506711 56.92366822284135, -3.887691925599399 56.92695379572427, -3.871541921782824 56.92274897176618, -3.866724875205904 56.92565137211124, -3.856477234563107 56.92212905073511, -3.850937629153611 56.92605689477471, -3.840174511276794 56.929055154628266, -3.832997803019164 56.93551313194939, -3.822941411384762 56.93893079057384, -3.818290348222801 56.93421843249534, -3.802487880371223 56.937115882766065))
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>