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/S02001325 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S02001325 geosparql: asWKT POLYGON ((-2.5364701244712498 57.67002332328999, -2.535739434557018 57.6694290701299, -2.536146170914901 57.6690660554342, -2.538065593252098 57.6685315700324, -2.538470447990915 57.668059715619236, -2.539909333944519 57.66801906200926, -2.539478366601055 57.66608967788376, -2.53943003747067 57.66509283372984, -2.5390136248835575 57.66301068375042, -2.5372598625116343 57.66342235592331, -2.5363287996080492 57.66279753725584, -2.53935912655247 57.66144626620076, -2.536975007851342 57.661159991288095, -2.536975572927412 57.65901563761695, -2.5386061201048165 57.65901888949805, -2.538602085540079 57.66006140004901, -2.540866250164771 57.6590633443824, -2.540607089779595 57.65883556187514, -2.53904707931481 57.65901701062568, -2.5359003488069725 57.656383977141545, -2.534737629600557 57.656311910783884, -2.533772336512248 57.656704291168246, -2.5330493333925395 57.65624415225447, -2.5322181225033757 57.65677870445132, -2.530735577750209 57.65738675908654, -2.529657900918589 57.657031979910045, -2.527535327285399 57.658576849605595, -2.527007445424169 57.65915392660497, -2.524074503794364 57.65798042501032, -2.5247049193135136 57.65753768035097, -2.5236531721981774 57.656652778757675, -2.5247335261477826 57.6560374944334, -2.5263867863219565 57.65448564316763, -2.527956699683262 57.65412878278284, -2.5291120349719294 57.65407005897122, -2.5300458789262943 57.65376074476157, -2.531341225723698 57.65296485288154, -2.5337597240228447 57.653349894676694, -2.534651438764345 57.65359763598607, -2.5363773464846484 57.653599309085024, -2.5373704321399653 57.65276870709334, -2.5373519702741754 57.65152021562645, -2.5370530059175955 57.648296793145676, -2.5371579289534285 57.647460978766276, -2.537655182295198 57.647099566810944, -2.539603127117933 57.64515105629747, -2.5409331978377865 57.64447168765593, -2.5413243846198488 57.643742433530505, -2.5410139184717653 57.64314193715409, -2.5402359478346037 57.642642245731984, -2.538540450941475 57.64239797044492, -2.5382816212205714 57.64188707208808, -2.538809357884509 57.64132791094307, -2.5381796393816978 57.64065689906175, -2.5373012676440903 57.64015762598719, -2.5360939505661975 57.638932153128366, -2.537641451862458 57.63824291329808, -2.537969634531242 57.63778341098445, -2.5377451382101897 57.63732625999115, -2.5356344109630293 57.63729930020464, -2.5339282830518095 57.637450228415155, -2.5273901563383396 57.63702855090696, -2.523242278631933 57.63626430430513, -2.5211048348716814 57.63553658045378, -2.520075442312264 57.63499288940482, -2.519073931680243 57.63405383798757, -2.5171863553137537 57.63321723224767, -2.51360607601376 57.632279689180585, -2.51185582040895 57.63166699878947, -2.5096150071360084 57.63069696442251, -2.5089857768328985 57.630007849921334, -2.508859015816227 57.62932569280313, -2.5071516288873874 57.62936847607592, -2.5053745161501437 57.62921391881729, -2.503335109666599 57.62946458335082, -2.502010212977576 57.63052978314391, -2.4989961899421873 57.63054171815416, -2.4975103454866394 57.63087094393295, -2.4949057436044555 57.63020748483987, -2.492767881758355 57.62938046917864, -2.4922101007725463 57.62899639688192, -2.4934392775470777 57.62826402482991, -2.4933597543430994 57.627339141802345, -2.4960446244790937 57.62285536458678, -2.4986419463398097 57.621803176524914, -2.4973134681532114 57.62014665381769, -2.4959746511295524 57.62017886276867, -2.493946795712347 57.61631535858067, -2.494689889647224 57.61556690600293, -2.5038411352862724 57.61764163272404, -2.5086709766889244 57.61587968133526, -2.509754408249872 57.614357274900996, -2.5111837058959985 57.61363290166543, -2.512183108442766 57.61328752000426, -2.5133403582645815 57.613453491337324, -2.5142341121572866 57.613925929446815, -2.5148387647148787 57.61289048054635, -2.5166506988245825 57.61083507568024, -2.515760980657949 57.60946438811567, -2.515641994227304 57.608153428614756, -2.516378598139239 57.60699167744081, -2.5162212439870597 57.606516247720855, -2.5160559256344355 57.60429823509452, -2.5161807436436825 57.603659976108446, -2.5179454090646844 57.60302397832527, -2.517228761454657 57.602047820605584, -2.5150620608710867 57.60264951820123, -2.514832609675462 57.6018060975086, -2.5151727836706446 57.601014249831955, -2.513785508518093 57.59993301537694, -2.513169033908874 57.59892947959921, -2.5122510074391617 57.5967055417956, -2.5126717990604504 57.59569779287538, -2.5156983291742185 57.59440995586516, -2.516003306774129 57.593501475701395, -2.516664507336258 57.59294185656198, -2.5160148038132357 57.59077074118988, -2.516406174166521 57.590059522092425, -2.5166257040841935 57.589025633571474, -2.5167441083692355 57.586761551342875, -2.5162694603756113 57.58631436569591, -2.516172858801861 57.58539854206664, -2.5148150286566504 57.583993826000885, -2.5167646301502646 57.583491824560156, -2.5184665328371767 57.58321537341972, -2.5202048043613234 57.58314534791413, -2.520042761811174 57.58233758658733, -2.5208373472972334 57.58176841213216, -2.5211222882380913 57.580644418799544, -2.522424125997501 57.58046837197831, -2.5247203125631255 57.579668388544704, -2.525521773216207 57.57842546428438, -2.526051904354739 57.578081911252895, -2.5271141773125816 57.57637979741273, -2.5271337159495553 57.57541857353051, -2.527855831303224 57.57448137132822, -2.529099873673476 57.572343040798536, -2.5305140368685404 57.56831576607014, -2.533718486077735 57.568098447511986, -2.534957485245835 57.56747047865012, -2.5345454137805774 57.56694088673371, -2.5358286254508777 57.56692611486819, -2.5372282720968644 57.566023517971324, -2.5366805044906937 57.565604178407355, -2.5342482390512115 57.56539793241141, -2.534745358620138 57.56316267881456, -2.53580083445765 57.5633185072026, -2.53907842810199 57.56342132917365, -2.541477949870462 57.56404882458147, -2.540325259892805 57.564770276097946, -2.5436218859499866 57.56434501974076, -2.546027231049405 57.56423583216449, -2.5470037848418072 57.56470768212486, -2.546890144137913 57.56604657909441, -2.5490186081461608 57.566414610648025, -2.550851741630813 57.56382862487774, -2.5524975879718244 57.56434242372805, -2.553989913423932 57.56465027538155, -2.554348203123462 57.564028904269115, -2.5551506064016363 57.56403435240658, -2.5553161557754103 57.56173409014643, -2.5585781841682786 57.56191731775127, -2.5648195639839795 57.556976067808456, -2.5694077603622754 57.5597041349951, -2.5778142637955668 57.56180380269289, -2.576705775623993 57.563578443930695, -2.5741494019512268 57.56643352737856, -2.5745757642709677 57.5669703103044, -2.576821097095003 57.56889051433992, -2.5776654519213382 57.56942538572838, -2.5789785199092625 57.569864845995674, -2.5806178970222162 57.56992917956943, -2.58298487433205 57.56949609188801, -2.584786918346453 57.5703231412661, -2.582305021421131 57.572984476325644, -2.585016061228262 57.57314261565478, -2.5868289769057826 57.57359231664695, -2.5900958542528123 57.573999275763484, -2.5866890438176644 57.56489780751821, -2.5870320888029634 57.564402169603596, -2.593458188945857 57.56383318210446, -2.596059633435733 57.563461614588974, -2.5969817354056195 57.56158888242133, -2.5956363500007176 57.56005919936112, -2.594629385852588 57.55980344982931, -2.5942064972737775 57.558467030108915, -2.5956537616041606 57.55703197296546, -2.594490045696366 57.556381726359334, -2.5919747578642753 57.55585458794402, -2.5865627681466794 57.55704758935906, -2.585686749740903 57.556611507977266, -2.586011577997266 57.556026130310016, -2.585599253736637 57.55324343055392, -2.5864625454284154 57.55081411381227, -2.5884282644155956 57.54733767024878, -2.5902582337972455 57.54478703997614, -2.5931701376735097 57.54509676473662, -2.59357989255596 57.54460977586042, -2.5933218714250277 57.54415287419602, -2.588729861796167 57.54324917270879, -2.5937985463053645 57.540593505033534, -2.590045154582815 57.53987453047903, -2.590711795549233 57.53874858125197, -2.5921547783316607 57.53708901169002, -2.590567413686921 57.53705153613591, -2.5896796105734765 57.537927004308244, -2.5887218108695604 57.53757216974642, -2.586915718283588 57.53743686818951, -2.5874991277620274 57.53528729152631, -2.586922345145818 57.531616060948764, -2.5845670716849343 57.5315820886558, -2.5846036657087472 57.52969556140605, -2.584509698041044 57.5279982742571, -2.5832402713918556 57.52797719987073, -2.583043181251853 57.52609175206902, -2.586067399358107 57.52621248233434, -2.5903727689316263 57.52604869010575, -2.5897734535265475 57.52512627797656, -2.5894305702002174 57.52353794786271, -2.5878067185984417 57.52223405325892, -2.588249807537191 57.52175590678704, -2.5895257117897046 57.52115709558117, -2.591368003301323 57.52048375658186, -2.5935635645041883 57.519979399892684, -2.596322844268222 57.51923879212175, -2.5994685524206442 57.518657976509985, -2.6003129745585376 57.51823177550622, -2.6024565690304846 57.51762870091815, -2.60437967565091 57.51682004420816, -2.605572907682219 57.51528726519058, -2.6056593405873 57.514460442565266, -2.6051496821384137 57.51392392660122, -2.6058179209686485 57.51295058850997, -2.6073763642300074 57.51231430648681, -2.608888126380235 57.51188483239691, -2.61072476341664 57.51192086821762, -2.6139130453732697 57.512929421708435, -2.616476517378976 57.51350079719362, -2.619370384064406 57.51386389704417, -2.6210752999319658 57.513999238890705, -2.6213694546157873 57.51362949058508, -2.6254625025385 57.51383384205643, -2.6266019384280686 57.514088686652244, -2.6268927718337753 57.51450044647342, -2.628226354160349 57.514395003270494, -2.6290064996904365 57.514139600305725, -2.6296934560049454 57.51428887962093, -2.631618427798247 57.517495067452074, -2.632881941578247 57.52008473816731, -2.6340027352904647 57.52117500147622, -2.6341035138603632 57.52217158413315, -2.635352499507058 57.52294678757084, -2.6373500008791333 57.523556520559445, -2.639257017199898 57.52376245882823, -2.642227499518046 57.52367551365374, -2.6437056966209007 57.52417999592508, -2.6464632908131964 57.52715714007857, -2.6480435026040436 57.52869406027648, -2.649822504655177 57.52957060683542, -2.650430830498855 57.53015943314675, -2.650631245123483 57.53091025231015, -2.6516368504467973 57.53345165979564, -2.6524521865851916 57.53431068480601, -2.6549630182421438 57.53490221541356, -2.6558109793081615 57.53496787712757, -2.658509663093284 57.534856812121866, -2.661599442351164 57.534116646940774, -2.6628668871108867 57.53401388147388, -2.6656389281202704 57.53408372920603, -2.668217589836776 57.53426412919507, -2.669215987838937 57.53479151398197, -2.669217697656578 57.53534034856163, -2.6683306223961187 57.53569447646914, -2.6674667973988924 57.53576821460868, -2.664450161698132 57.535114022054664, -2.663665503502562 57.535224146499225, -2.663462778444945 57.535740819675574, -2.6643107639944184 57.53663193492207, -2.665476936403302 57.53701653919323, -2.668458444370833 57.537658317827926, -2.6697632131803783 57.53758133568602, -2.671515230512526 57.5372109215041, -2.6730038366421898 57.53705028662751, -2.675351521811607 57.53701079827106, -2.677321349131665 57.53713139033465, -2.6803287101219 57.537714362947966, -2.682825074093911 57.538477887461, -2.6857680481744137 57.53900179339588, -2.6868113833900167 57.53896737578233, -2.6892123657549942 57.53855994671922, -2.6946387634237423 57.53791488261674, -2.6957013421420153 57.537577567558245, -2.6965700964641814 57.53677663579659, -2.698883426778604 57.536974313841526, -2.701261738908335 57.53818277388742, -2.7040026316561003 57.53912866838371, -2.701227077207494 57.540725079130915, -2.7000680316213916 57.54126149372111, -2.699233402171211 57.542164392540435, -2.698633239574985 57.543101918989194, -2.698625648019215 57.54357803632551, -2.6979953598678525 57.54381508287607, -2.6966774607704695 57.543912190606854, -2.6970634649614245 57.544880193367895, -2.6950688260539253 57.54541218977915, -2.696483104424638 57.546859594658706, -2.694332185851094 57.54708702875887, -2.6974733814908416 57.549719613123926, -2.6853190111632625 57.550226332153656, -2.6856546705527427 57.54941606626691, -2.684056148071107 57.547035338951204, -2.6823668562960976 57.54693668926316, -2.6826003037179627 57.546019191191554, -2.68101252198817 57.54419529499687, -2.68002793371431 57.54335622856038, -2.680299345309281 57.54268106295499, -2.678975066564986 57.54153840650965, -2.6779240992074045 57.541615917089935, -2.677674577555502 57.540772882326635, -2.6763590460758104 57.540995523422275, -2.6753207187056125 57.54175562137883, -2.6755301357811794 57.54223957590645, -2.6742342838913604 57.543531031029694, -2.6710475442576205 57.545569119764075, -2.6700368465428173 57.54596080740555, -2.67251466415789 57.549028632842244, -2.672682465609219 57.55269267691113, -2.672872433479195 57.55483852687083, -2.673966542645318 57.55888388141275, -2.673509532431363 57.56219194573504, -2.6733822470383566 57.565255716388464, -2.6728838599896423 57.56723456054939, -2.6720213070218084 57.568505709861086, -2.6719357488031243 57.57021287144635, -2.6733257321860084 57.57124745690285, -2.6759790225246913 57.57368554943746, -2.676285889697432 57.57490554845931, -2.676161471967498 57.57540924359266, -2.6764901296049612 57.57600033909718, -2.6732453525438147 57.57685306474536, -2.673567547769287 57.57800112661845, -2.6716177745069785 57.577454585428825, -2.670509452809439 57.57810722522253, -2.66920179019513 57.5792183259134, -2.66720732835236 57.58041043701382, -2.6662623007249793 57.58003926838387, -2.6629714681719396 57.57998337642907, -2.6620620491461753 57.5807104948456, -2.6632922738730413 57.5821426192161, -2.6636979791554722 57.58329923955342, -2.6639166000563175 57.58511600578755, -2.665902125158646 57.58700142036909, -2.66562505582321 57.588085827047664, -2.6641387897621933 57.59096809162406, -2.6645314876141293 57.593238631068786, -2.6645478741116326 57.59413679835301, -2.6618941835133145 57.595399323001324, -2.6708622954699757 57.59727430106978, -2.673011046812165 57.59766709111966, -2.670930964776732 57.60100172451324, -2.6702027630329668 57.60203338944905, -2.6807865148978713 57.60476364735105, -2.6798943297176763 57.6052115728253, -2.680060400320204 57.60693534203928, -2.6808715524148568 57.60825140972215, -2.6828604587339857 57.60900420892921, -2.682153851168227 57.609699686835945, -2.679679500355576 57.60983877632141, -2.676413597612079 57.609712578467935, -2.6766535178774356 57.610914963816924, -2.6769835106674327 57.611559953278096, -2.6781293763290526 57.611975983174275, -2.67831899603344 57.614067913191995, -2.674565031620875 57.61381852874593, -2.6737723847364965 57.615304886665236, -2.673055847724391 57.61547938319356, -2.673465682788771 57.61591733829661, -2.673303506594945 57.61710390552306, -2.6691414451456024 57.61652417672938, -2.6683833148579454 57.61808217733067, -2.6691526687853524 57.61986564213586, -2.6710365641127707 57.62034969643099, -2.6697952885246625 57.62203602500457, -2.6706714222784957 57.62233678704001, -2.669591385790527 57.62278266020375, -2.671351953739374 57.62383326639151, -2.673064393017848 57.62499189555351, -2.671617063915583 57.62567025205301, -2.6768443679136382 57.627477852935634, -2.679540363406823 57.62569381785991, -2.6804606006678036 57.62476366015727, -2.6838912033126126 57.625562561182335, -2.685924741800213 57.62596474168811, -2.6854691687751178 57.62666785549494, -2.6847587418742385 57.626285454542874, -2.683996865160205 57.62672972668656, -2.6842782572007895 57.62744681112381, -2.683884539906305 57.62788010628875, -2.683001387557555 57.62810944608426, -2.682816826490376 57.628981754397245, -2.6837853941437104 57.629731056241475, -2.6828983011659306 57.62975381689475, -2.6824889784840575 57.630250069837984, -2.6840042045165142 57.63068202680409, -2.6836479894863126 57.63133070004115, -2.6826042182875294 57.631929191192846, -2.6801240422557635 57.63273301759251, -2.6797250562913835 57.633786134479216, -2.67921114487268 57.63406735662889, -2.677271491211867 57.63423046690031, -2.676907431461742 57.63446596379973, -2.677820244830455 57.63491918425817, -2.677800647051694 57.63566484316821, -2.6835133246566234 57.636640134624216, -2.6853084721416955 57.638579635939344, -2.683227793277713 57.64016284793363, -2.6811886096012483 57.63950015828968, -2.6802754151396995 57.64082551321822, -2.6828844623271517 57.64150310613519, -2.680263652091197 57.642882584814224, -2.6804359168475282 57.64403142642038, -2.6796982770260387 57.64489772016203, -2.6813462368242305 57.6452301970106, -2.6801640974792247 57.64741033281444, -2.6785565948878634 57.6474548997938, -2.6762372825548173 57.65516537238998, -2.6719570177696848 57.65653671938168, -2.6707882947584576 57.65500575947977, -2.670625078978828 57.65342569738405, -2.6633864246521344 57.65342793897449, -2.661341051564855 57.65336680104331, -2.659706194780476 57.65192016932245, -2.6601907539459475 57.6518457801418, -2.6593150639764924 57.64883221527458, -2.6575744256550937 57.64893110468248, -2.656318096801057 57.64987181597233, -2.655018483597032 57.650273786440856, -2.6546596201211967 57.65081459707726, -2.6559956258680524 57.65149932861627, -2.656250314565689 57.653130987157866, -2.6545532582317657 57.65227233049476, -2.649969291367047 57.65087472294941, -2.6500141844423837 57.648700718880924, -2.6492162966973485 57.647177786844175, -2.6463944863186373 57.64677006467531, -2.6432260444683675 57.64665148465351, -2.6392443793638325 57.64696810079704, -2.633696264875774 57.647768525569454, -2.6287227721076447 57.64887124695527, -2.6247816515259355 57.64961837477608, -2.623777143365291 57.647710058151254, -2.6198963152722015 57.648061487930796, -2.6155365869169467 57.64882834408627, -2.612529293409036 57.65231019513829, -2.6097489427131553 57.653374585129974, -2.5995425693453336 57.656306767172445, -2.599904680985747 57.65692484155435, -2.601600848092172 57.658156367194564, -2.602684838865421 57.657836818771955, -2.608162617634744 57.660711938860835, -2.607570889955733 57.661406434493855, -2.6064436074296102 57.66214840881852, -2.60722262103911 57.66262972516471, -2.6087833200511197 57.662747977078, -2.6081281424447758 57.66365836005115, -2.606016464689123 57.664674533949835, -2.607863220753504 57.664854303820206, -2.6079003495681925 57.667072789072286, -2.6107024813263466 57.67023011434175, -2.5980513165131436 57.67056901963112, -2.589552431069671 57.67059993536634, -2.587926734087113 57.67476637979664, -2.5872848535521418 57.677580868846775, -2.586200586115092 57.678141929416306, -2.586445553617083 57.678638022828146, -2.585645341211793 57.6785370161177, -2.585444064522744 57.67790917643312, -2.5846219689374332 57.67756625586559, -2.5833326765959193 57.67757310592399, -2.5811899895386268 57.67831683399747, -2.579957402138127 57.67967075546236, -2.579142038836067 57.6795388559371, -2.5782847848282824 57.67972422282807, -2.577260468534103 57.68068732728523, -2.5777932801273056 57.680870831409976, -2.576742774732459 57.68166607942202, -2.5751818549863166 57.68242501563307, -2.5744155592608484 57.68264138093846, -2.574246341209347 57.68201517524419, -2.5725930826152155 57.68160229087219, -2.572061374002602 57.68106215729537, -2.570559827016519 57.681228825572475, -2.569696788483181 57.6801961421642, -2.568372607288538 57.679373019785814, -2.5679138955089362 57.67781213618683, -2.5683956434929645 57.676560515467024, -2.5674058141322433 57.67577180989098, -2.5673531919707604 57.675086685804544, -2.5659497260026694 57.674539654541505, -2.5642754361761257 57.67360846953917, -2.5619604816427923 57.672981022115216, -2.559594203981709 57.67260796256372, -2.5588140943738646 57.67213713866531, -2.5566169838963932 57.67142014702593, -2.5529253368952416 57.67053090904289, -2.5497918956755155 57.67007119369691, -2.5474990691503834 57.66987903450307, -2.5443904180810244 57.669946347153, -2.5418788346586703 57.669134341579664, -2.540965657123362 57.66905022276883, -2.5392738422448886 57.66970058942943, -2.5381669295096025 57.66955260279437, -2.5364701244712498 57.67002332328999))
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>
<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>