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/S01005511 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S01005511 geosparql: asWKT POLYGON ((-1.378544970193872 60.28664294413439, -1.378425814740764 60.285890336157564, -1.380412103534031 60.28486781488593, -1.381303380699838 60.28566155342522, -1.382722771381589 60.28565541872919, -1.382702514667028 60.28636885046675, -1.38326336161144 60.28637145386735, -1.383921763284404 60.28566204086734, -1.385400620326628 60.28556189658586, -1.386381161028634 60.28438908859329, -1.388168807779662 60.2845664139532, -1.389419474392957 60.28569047928345, -1.391210815944607 60.285327790527674, -1.391898634414002 60.28724343698032, -1.393453505151565 60.287268499598895, -1.394410754948263 60.287954744747175, -1.396458707269296 60.28712245437027, -1.397619466091582 60.285837269076225, -1.397125936867413 60.284913281517525, -1.393917978315439 60.28270953497453, -1.393254140075 60.2809667005176, -1.391769205996383 60.27971554854311, -1.389704447375006 60.27970608331943, -1.389372661993559 60.278868066691274, -1.391135379014204 60.27891994651277, -1.402168750538241 60.27683876184399, -1.399191805570589 60.275146156974614, -1.390414759534951 60.272708824017585, -1.397501468505785 60.26580046877694, -1.403161065935571 60.25870575307985, -1.405199827422444 60.25987317524295, -1.408091874621185 60.258826581452055, -1.405827126026276 60.256167698845644, -1.405127999519595 60.25417519622694, -1.417015281572716 60.2579771302969, -1.422530678683112 60.257731853733574, -1.431634383173186 60.25582269966774, -1.436302792996342 60.254370056417, -1.418040900915418 60.25210943773944, -1.413761862982712 60.25196491633477, -1.408937278964657 60.24839666554622, -1.408796091016643 60.242811364246876, -1.404409308156315 60.24270197610996, -1.39576512150817 60.2403643244672, -1.39070189006941 60.23780015245166, -1.384998769669259 60.23569972645231, -1.379647079643199 60.23797344055119, -1.376953767522905 60.23525816985937, -1.37631233495244 60.226249269041205, -1.374627699233741 60.221814716510224, -1.369891802664484 60.21747343602412, -1.362751821723234 60.214341599637855, -1.360112568656064 60.20994715387211, -1.360560174444958 60.201778421312774, -1.362070694863306 60.19830183790832, -1.360417369361625 60.193355422268304, -1.364547397551953 60.193339352788385, -1.365024713330415 60.19103402994117, -1.369426455242876 60.190938299514734, -1.369614809366374 60.19145997821006, -1.370068038311659 60.18945083254392, -1.374172630595633 60.19074527839245, -1.36959601903921 60.193381395988425, -1.36721007771239 60.20585085015074, -1.367811209893703 60.20930164760876, -1.370489657080271 60.209817203015284, -1.374593353568303 60.20939663327189, -1.375232902638321 60.20707409083212, -1.377780877942614 60.2059008363156, -1.378707211593422 60.203660429459, -1.383306138344615 60.20275704614816, -1.387147737358873 60.202792804075436, -1.392511371176333 60.200509870573725, -1.395678885948032 60.202858867934, -1.394817577687256 60.2035912174662, -1.3970826101979 60.205989934755706, -1.394247028380929 60.21008040945315, -1.394096902088925 60.212351400868236, -1.395142038145533 60.21733051120794, -1.397739407450408 60.2174051725618, -1.399933010378176 60.21191998797533, -1.401833499152848 60.21159634653313, -1.404226084978271 60.206022197472514, -1.404442421236876 60.204038815983104, -1.403012494261479 60.19933639208815, -1.406324881720112 60.192697832922654, -1.405020244268039 60.19005216992636, -1.40643924580095 60.189358164110615, -1.405933465610644 60.185414127406, -1.40204379083074 60.18416652679979, -1.401115647657484 60.18266284924153, -1.403383835755224 60.17986264347308, -1.403012696231021 60.178460249680626, -1.408327784903859 60.176589500700096, -1.412724995119853 60.17360108100567, -1.413970867378537 60.169422376447784, -1.419145034559355 60.16520705297201, -1.42309958797556 60.16368890990588, -1.424275145294912 60.16446621274819, -1.421730543111157 60.167777370949906, -1.425392939889657 60.16752392096771, -1.429260357634523 60.16583461519928, -1.430102173401739 60.16820869016217, -1.433045675617916 60.16784418933923, -1.436064901872767 60.16831499300275, -1.43506786428459 60.170762011421324, -1.435948396274518 60.171959963405925, -1.440130226623064 60.17085531236329, -1.439296608465581 60.17370637838902, -1.438113931490436 60.17403283996323, -1.438763117620643 60.17497896497606, -1.435957220004884 60.17744026829392, -1.436047800120103 60.1781290714211, -1.43869268373593 60.179109166901355, -1.433069403643492 60.1816604366945, -1.431858224617212 60.18361851446313, -1.430831334328478 60.18379258809332, -1.435426646861724 60.18748377843604, -1.435517658238455 60.1881470815275, -1.438382517107887 60.18828672411209, -1.438443277086777 60.18772604873045, -1.436263687670777 60.18644196251833, -1.438481135177858 60.18550798467453, -1.439271197373314 60.18421098438051, -1.43948904674448 60.180438367407824, -1.441339045022541 60.18001273150865, -1.442029093495062 60.17856230854307, -1.443048408753338 60.17882156934592, -1.444098764858412 60.17724516476458, -1.444968826847716 60.17724880862578, -1.444831628601411 60.17627936058945, -1.447153063889111 60.17519268867578, -1.448966407784066 60.176934018790526, -1.45136802753232 60.17717345025713, -1.453380122476049 60.17621287410908, -1.453391977526805 60.17549901456493, -1.452222360189066 60.17481034379812, -1.448034453750531 60.161604181990896, -1.44798305147675 60.159296366194496, -1.451280145241384 60.159274136878146, -1.45237787002182 60.1506768025344, -1.461538747939104 60.14555140764542, -1.466017861117106 60.15251028649276, -1.465638391995669 60.15480737742007, -1.469005181006764 60.15713748345333, -1.468301468944292 60.15944225910486, -1.470699156695836 60.160457497537216, -1.472498539175304 60.15946800187922, -1.475271788412931 60.16179558184928, -1.476173212259736 60.159491551540526, -1.479380789289014 60.16171300972132, -1.480183087457472 60.16110558795746, -1.484441050267893 60.161858488186866, -1.484873471873327 60.159552574101625, -1.487831797412217 60.15930364566756, -1.48899837675928 60.159586495497166, -1.489035096956241 60.16650941111715, -1.493629332334372 60.16654499097645, -1.494702468581803 60.1647173791916, -1.494307522092108 60.16344984262769, -1.494941826429807 60.16203358407159, -1.498192465203228 60.16271036985977, -1.498203956353114 60.16195618160482, -1.502275262692042 60.16198050444227, -1.502780750416014 60.164298969623374, -1.50420276008709 60.161996703615856, -1.507321035566167 60.16310375928477, -1.507374834089144 60.164325095157345, -1.510799469166081 60.166663317913205, -1.508458875872524 60.168953270195466, -1.508586472988296 60.17127030653815, -1.510047691325072 60.17359227696045, -1.511993628721811 60.17362638617337, -1.512004566857734 60.17653559735003, -1.511040549768175 60.17833681183348, -1.512018998464431 60.18285680756902, -1.516595628247818 60.180565984793354, -1.524959066141733 60.180623136605384, -1.525785607961028 60.17955760316924, -1.525788109106821 60.18063508091265, -1.530044983386918 60.18297576667374, -1.53036647038618 60.180660346826365, -1.530865810646699 60.181039229403225, -1.533610944696596 60.18068077428676, -1.532731972080057 60.17910637311559, -1.534544855322005 60.17837647492887, -1.539559136314241 60.18071951064363, -1.544184244144827 60.185180035528624, -1.546100578169159 60.190026223969056, -1.54789920992246 60.19035560448704, -1.544626180863927 60.192328743946725, -1.546957314252851 60.195901335885814, -1.54465371145956 60.19815612679502, -1.539661801950016 60.19915351573957, -1.544300579936994 60.204116881844165, -1.54001893277512 60.204569012423015, -1.53580764254587 60.203862978156806, -1.534128811046313 60.20394688253721, -1.530485794895298 60.205146193006094, -1.530484092219549 60.206528933671436, -1.52095151338384 60.208254728283514, -1.516833624460272 60.20855406053994, -1.512858314886578 60.20774938842996, -1.507933194602914 60.20894336990707, -1.506326282377149 60.20814314887892, -1.507268639193191 60.20737698991917, -1.504927540895667 60.206348412237624, -1.501761592213773 60.20567365165858, -1.492046623108938 60.2044894750775, -1.484310803220831 60.20453613111061, -1.483876203699799 60.2061152409403, -1.4816094277051 60.206922300978725, -1.481598170628059 60.20763616038521, -1.482767187460347 60.20822714226059, -1.485321418358022 60.20869601826887, -1.486979848283799 60.2074785994608, -1.488777980972448 60.207154080154176, -1.491692786382648 60.20749673334738, -1.495858241109449 60.20646725215904, -1.499546495471172 60.206481211060336, -1.501795805969799 60.206795640004216, -1.503204360974496 60.20754906582107, -1.503980201627927 60.21025753023446, -1.497234405561569 60.213653102663585, -1.476284500436339 60.21705590788054, -1.473645631867172 60.21843719963702, -1.472444232116645 60.22020127109827, -1.471149288371183 60.222162496276276, -1.477962299023638 60.21936111203208, -1.485690568422892 60.21796363768544, -1.503087429653645 60.215605601858584, -1.507900921621531 60.215919835128, -1.506484049976513 60.22014362295079, -1.505657686358484 60.22828437576143, -1.49476410252439 60.230990829994575, -1.492918591399951 60.23098379514136, -1.495009443933275 60.231705663307444, -1.498900549526956 60.23205185771764, -1.511260578567002 60.231766471564676, -1.51661854423391 60.23299372986562, -1.520578485434507 60.236303316457104, -1.522247385371575 60.237018658470944, -1.521617372178242 60.23812078776999, -1.519018924800369 60.23963868301136, -1.514877544072718 60.24027007118704, -1.51188631020741 60.24140645293347, -1.513197504494041 60.241589745564994, -1.51245955044261 60.24193042610419, -1.510986476813096 60.24746494732779, -1.504490699568418 60.24501763080233, -1.500888770519208 60.244781570203, -1.500796821103355 60.2523474421224, -1.496605775415761 60.25233162684272, -1.496131692954062 60.257322056599634, -1.499591451620909 60.26386273258322, -1.492066886298304 60.264283121897776, -1.491387494593942 60.266139137810356, -1.488778519157968 60.26886766430603, -1.486760703222363 60.268446861890425, -1.486616721188385 60.27302549838564, -1.482043281529812 60.275306327905334, -1.478951130815085 60.275523195446084, -1.480578913053645 60.274609612689126, -1.477565354051344 60.27464314456045, -1.475798071533147 60.276676818247054, -1.475874864559174 60.2775840716022, -1.473044373315923 60.277572879531874, -1.472215307571594 60.27802305580584, -1.474566773428534 60.27943813978701, -1.47684016747725 60.28003661987381, -1.475625516373634 60.28175502599387, -1.478758460272718 60.27999881254174, -1.477980289619137 60.28298867187638, -1.473033615579661 60.283921445279724, -1.471553415163497 60.28509460173105, -1.470388157360753 60.28372954167054, -1.468972003044872 60.28658076864254, -1.470051113749682 60.28762806143824, -1.466744629203429 60.28874851878396, -1.46472927510448 60.28910320071584, -1.463195846593277 60.28791799206402, -1.459707918198887 60.28894684906312, -1.461153664849547 60.28990500898773, -1.463523326443614 60.29023202113834, -1.461034735379007 60.2915823687923, -1.460931441095552 60.29230750805654, -1.462208813341424 60.29240337614673, -1.465167473409567 60.29023864572219, -1.473879880247065 60.288096743658485, -1.478243062200572 60.28942900966791, -1.47794520789309 60.29092429952182, -1.481145102973377 60.29075543681659, -1.478555738387313 60.29274057956407, -1.480271214115686 60.29401701446356, -1.480979761504287 60.295425545400555, -1.480282718064061 60.299050589897945, -1.481829263825725 60.3023669648754, -1.482640175876998 60.30309567871688, -1.484466301825198 60.303193466993505, -1.485461496544792 60.303832173195744, -1.488557767536792 60.30452433129217, -1.489003367401227 60.305251590260035, -1.487055899915818 60.3070579745865, -1.484947527253401 60.307457954791694, -1.482502942907947 60.30599735379685, -1.48066803589924 60.306443672764466, -1.479125265595613 60.305757434667825, -1.476902323111842 60.30760793338993, -1.47507306037525 60.307691429345105, -1.471535191676315 60.306044917430505, -1.470032284161103 60.30290998452513, -1.467209916315332 60.30226385358162, -1.467879763310759 60.30040729728573, -1.46488454911456 60.2991709048282, -1.460847999420021 60.30015224039796, -1.460491486528107 60.299606626682646, -1.458667900621916 60.2993724817694, -1.457945952547058 60.2988253718804, -1.456013730301812 60.29963373415152, -1.451913560405836 60.29893668002016, -1.453036471624982 60.297354157603145, -1.451567859693079 60.297756231363884, -1.450474554402818 60.297570327552116, -1.453890470038734 60.29545308661131, -1.451692609963804 60.29576146760266, -1.448554420064726 60.29765307273568, -1.445321829648463 60.297004763062574, -1.444121059085853 60.29777065065883, -1.443360104886571 60.29953601344504, -1.444810448611172 60.300222282490786, -1.448840616901126 60.2996495384769, -1.452486225416431 60.3002087678377, -1.453755561031542 60.300803501041706, -1.458688845239537 60.300869016462386, -1.460323812543002 60.30146518339071, -1.463516659273599 60.3017955311701, -1.463402259053023 60.30320083305011, -1.462212103416439 60.30333206187041, -1.462203911511908 60.30383084510981, -1.463105070989743 60.30460538773515, -1.465934211694438 60.30484351911781, -1.466291614764805 60.30534377095865, -1.460972696624234 60.30645599718567, -1.456769656043947 60.30639355115655, -1.456120900352774 60.30693506056275, -1.454661714164271 60.30674770271192, -1.454433971009743 60.30717251659869, -1.452757507040374 60.3066147970641, -1.450855605796314 60.30672368317399, -1.450987114895151 60.30751435950629, -1.446044028865675 60.30801885032207, -1.445106256197659 60.30767642331662, -1.441960338841584 60.30828267897679, -1.44608053999224 60.31015095305725, -1.449483172641012 60.30809795716383, -1.452684326051136 60.30990971011068, -1.456350908331868 60.31034675208844, -1.456156967819127 60.31112711388535, -1.463062270183671 60.310001522024216, -1.464879826803758 60.31064370955165, -1.463858854235762 60.31159188645019, -1.463485734992539 60.31340157065677, -1.462267784192277 60.31385281865382, -1.460715358523438 60.31375583879581, -1.458814839828035 60.3145678455281, -1.455109653486067 60.31750673469, -1.453256178848414 60.31793011029127, -1.451184961434676 60.317302045461794, -1.450096663995181 60.31743223330161, -1.449306102424961 60.318156242574936, -1.445872536826123 60.318878244830174, -1.444299698110518 60.318754957580126, -1.444111665236904 60.31916719658561, -1.445808961184215 60.319425684407456, -1.44683548572429 60.32081268739288, -1.448141137778105 60.32068343053453, -1.44941931285613 60.32111072736128, -1.448956163768757 60.32173732446643, -1.449917422268543 60.32271100982526, -1.449035338510689 60.322411061018016, -1.447166136234847 60.32267266761, -1.446323474256011 60.32218431125769, -1.446878867826234 60.321459339396384, -1.445946184447884 60.32094366800961, -1.445642092993241 60.321795385455054, -1.444915381879797 60.32194499334294, -1.445230896770589 60.32148839209254, -1.443874402070974 60.32141089792925, -1.442316139297669 60.320425687788486, -1.441872955714593 60.320935619348354, -1.443264023854059 60.32217154242282, -1.442661724663104 60.322456341160596, -1.441682607156684 60.32254202141204, -1.441350755515195 60.32183130499033, -1.439861998186078 60.32207645037229, -1.436926321806496 60.32118413729794, -1.436482889335148 60.321703027930425, -1.434629407787642 60.32209921037733, -1.433982282264003 60.32287761062199, -1.43430864008917 60.32593638040047, -1.430929386480072 60.32542502994622, -1.429860670860414 60.3265089793963, -1.430459585344072 60.32774204839606, -1.428149194220868 60.32886799983938, -1.423510307053244 60.327402845382124, -1.423008959717484 60.325367244974146, -1.425652605874928 60.32192607296983, -1.424441594610466 60.321813093375745, -1.423907915355483 60.32230461755296, -1.422160622114058 60.321803204781496, -1.422105653185098 60.320815298011766, -1.423236071562547 60.32036228753867, -1.422815555586776 60.31957032979305, -1.421385036303861 60.31754388403164, -1.420463493005567 60.317450084994505, -1.419954216202195 60.31554435952817, -1.418534083830802 60.31499045268757, -1.414825553139251 60.31791025542706, -1.414721881937987 60.318646061940335, -1.412217022698134 60.32002673205332, -1.412663123847506 60.32038785456185, -1.411666374963463 60.32044629959947, -1.409775847891881 60.3198722617619, -1.408613271822985 60.32009156735754, -1.40719085996127 60.31966323110289, -1.40788538913807 60.319298194405526, -1.40499453042261 60.318988994731434, -1.399477287257359 60.316791325501164, -1.398925547109662 60.31726471057223, -1.397387757501726 60.31623416801517, -1.396664592521323 60.31618599642042, -1.396530940679995 60.31656249870888, -1.393749199422936 60.31624457044427, -1.394704172441027 60.31550367673983, -1.389702530855006 60.31484332290524, -1.387773197552881 60.31347865263437, -1.385815794415418 60.30783091869344, -1.387185929464632 60.30617615426995, -1.389533487773816 60.30643835946586, -1.390287897325576 60.30576840770595, -1.385185682830638 60.30187503493192, -1.380819926632672 60.30023858305265, -1.379565069527009 60.29867041061136, -1.379746077945758 60.29771051733932, -1.382245880356562 60.295621103976096, -1.380128835986711 60.28704541013165, -1.378544970193872 60.28664294413439))
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>