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/S02002307 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S02002307 geosparql: asWKT MULTIPOLYGON (((-2.129059838011165 55.73904150788393, -2.126459154591392 55.73906668002155, -2.1242051914235653 55.738443622946, -2.1225162552832106 55.737689677722294, -2.123286511361321 55.73751549382577, -2.125385436858332 55.73749090286094, -2.126837311584936 55.73781287224767, -2.129776976479031 55.73869931842932, -2.129059838011165 55.73904150788393)), ((-2.0543525287751696 55.829887667128716, -2.0526400071330024 55.829145797505554, -2.0524222790288826 55.828679573068044, -2.051765680380526 55.82828721100911, -2.0518608704367387 55.827848706082825, -2.0529358361295476 55.8271815640365, -2.052700248349412 55.826488028851564, -2.051470346618133 55.82586409923891, -2.0494563437708195 55.82615334597916, -2.049074310854977 55.82572312142575, -2.0496818440589766 55.82524937024042, -2.049396723693029 55.82445970980639, -2.0501367151051704 55.823990395204305, -2.0498549878410084 55.823357072201226, -2.049251172215275 55.8229628779056, -2.04885615439882 55.822334090525885, -2.048194962978265 55.82198394008526, -2.04794508378866 55.82125535958912, -2.048162271904135 55.82007824691913, -2.0477182123998765 55.8197621509204, -2.0464489838951483 55.819370895860246, -2.045897895890544 55.81894881151015, -2.04568974405224 55.8183666650257, -2.044793670866269 55.817681445131385, -2.044686059966825 55.81708308706355, -2.0441106519454166 55.8162791431629, -2.0412045176578744 55.816076198772066, -2.0403263984160818 55.81564970658239, -2.039912150927209 55.81473068223358, -2.0388356895629096 55.813785812252874, -2.0385415259008703 55.81322434590361, -2.0367169974262085 55.812493532757216, -2.0352097930061985 55.81146789486624, -2.034382928347834 55.81107189401146, -2.0367783651383617 55.809905847192766, -2.0373494445090983 55.80978437697752, -2.039365352744168 55.808973300843626, -2.041489248081185 55.80776861368589, -2.041846101701982 55.80728510114745, -2.0441518763896545 55.80623664360304, -2.0455021537029014 55.80538257708501, -2.047989504340902 55.804271983269494, -2.050937828582981 55.80322943364161, -2.0526278222367225 55.802514413547755, -2.0528959902089468 55.80264008749685, -2.0559289259307145 55.80292715673559, -2.060032929652762 55.80258019048826, -2.062232990272012 55.802736329220906, -2.064814262473688 55.80189579435811, -2.0671451881088743 55.80025028911587, -2.067087962443276 55.79851711894691, -2.0725196331739713 55.79707822514415, -2.073406490103887 55.7962537745569, -2.0750679882669543 55.79519254039497, -2.076266504965889 55.79475243482058, -2.076965416162752 55.79412035365778, -2.079302666342051 55.79371004695709, -2.0806296188292013 55.793723557240604, -2.081794235106414 55.793898891335274, -2.08343387888385 55.7932113335685, -2.084562302643785 55.79287901445257, -2.0857185947868344 55.79289887690327, -2.086250413560569 55.792513946539714, -2.0872329938804093 55.79116999583151, -2.088102535079819 55.79064195525877, -2.0883080479961205 55.78984753435548, -2.0881457828348924 55.789317536697396, -2.0885389010818662 55.78687692948241, -2.0883788469494133 55.785912056506035, -2.0877471207487117 55.78507690563212, -2.0862588506985764 55.78408871363578, -2.0858425478777813 55.7825759319926, -2.085919118888339 55.781149060123475, -2.0862582119541764 55.77948300228994, -2.086814725469271 55.778102512492524, -2.0868218645509438 55.777014422989275, -2.0865216365083596 55.77534432194949, -2.086842091165505 55.774646858430366, -2.0875028801125546 55.77218269765904, -2.0873850211663507 55.770804480165246, -2.0857036090655594 55.76798796523543, -2.085754576630277 55.76724846224398, -2.0855031526698715 55.7659754600389, -2.086101457687606 55.765551846471844, -2.086014838563692 55.76457703196095, -2.085698195350718 55.76407858478379, -2.085661759184426 55.76272816046765, -2.0885868892438064 55.76311692976144, -2.0947452445294568 55.763381875125305, -2.096113972104451 55.763303538365264, -2.098884276942869 55.76291048632423, -2.099947193606685 55.762904233389015, -2.103263401842425 55.76227343151569, -2.1048472327790795 55.76161258600999, -2.1064146064823475 55.76078012012911, -2.1077840030372754 55.76040874061937, -2.1100361396929137 55.75833479083968, -2.110387175623292 55.75738026417768, -2.1100272706160315 55.75519183155731, -2.10848823369049 55.753502217634555, -2.108145196613323 55.753323718278125, -2.1071009650053925 55.751916678103356, -2.106740241111633 55.75108946975604, -2.1067407929729787 55.74954493920839, -2.106934634670241 55.74877744688383, -2.107667832383762 55.74834731966365, -2.1094467195523543 55.748167840502255, -2.1109733095508045 55.748341676795704, -2.1124493848459482 55.74867098188287, -2.1140346660257086 55.74874768773919, -2.11515381697369 55.748495060329915, -2.1162095951908015 55.74782917029123, -2.1180757266504537 55.745969277941995, -2.118940600327879 55.74437628966882, -2.11915137421542 55.743502737146606, -2.1191807542678185 55.74164909017139, -2.118340155863757 55.741244677945076, -2.1177065072314805 55.73974478193061, -2.117713044873679 55.73927216113114, -2.1189228028241947 55.73853691367067, -2.121263938395855 55.738024268718455, -2.12327178841329 55.73840053801645, -2.1252651667904994 55.739217956158576, -2.1267203541322446 55.73955969063658, -2.127682359224657 55.73957306887807, -2.1291819850197387 55.73985722349299, -2.130569586663737 55.73997435686627, -2.1360751349875096 55.74080038916567, -2.136629617714672 55.74040892228193, -2.138724237364999 55.740475756064804, -2.1418439094907575 55.73992589579716, -2.1440110039069857 55.739351920119795, -2.1453183214170584 55.738858894876486, -2.1465345413824286 55.738124538318935, -2.1485024419964374 55.73897997381269, -2.149873854838981 55.739436544536225, -2.151085164648042 55.73966867045743, -2.151118999962638 55.740180777819326, -2.153114840369424 55.741454182836875, -2.1545812466401104 55.74173088095992, -2.1563832855349303 55.74229465639603, -2.1564974235761203 55.74295042079416, -2.156020917612581 55.74328347519179, -2.1567271583202965 55.74463033487404, -2.1596877278476345 55.74410538336576, -2.160215278779507 55.744571927995246, -2.160858896741157 55.746143463123396, -2.1632317337125477 55.745996568255364, -2.1608640803663985 55.74740136505211, -2.1575569189194552 55.74894210172999, -2.1593210934458766 55.751841987957384, -2.1590948682806688 55.75496908866926, -2.1608960798365042 55.75516441121156, -2.161754633122448 55.75856861552361, -2.167250036720795 55.75812098177181, -2.1683961209129627 55.75784986308276, -2.1751736404102187 55.75908929789795, -2.179538114510051 55.758750553260825, -2.1823419104266764 55.75861163516079, -2.182525262387432 55.75693115830576, -2.1828213909733583 55.75552006436652, -2.1808800165471474 55.75261178304787, -2.176069369153801 55.74617736185763, -2.1725580813813212 55.74419293925905, -2.171803644202996 55.74312780269914, -2.1749544416014066 55.74269512216085, -2.180015288407665 55.741605603977725, -2.1804377483988793 55.742523087190165, -2.1829948581830836 55.74153904696193, -2.1884848322467727 55.7405154236661, -2.1928907861879168 55.73934051705828, -2.1959753970816713 55.73832031568186, -2.1978684397093278 55.73789497909069, -2.1992699192898373 55.737892711346454, -2.197840134407758 55.73230630115207, -2.1971989842097672 55.72831795189166, -2.1961543228533564 55.72637884540268, -2.201660821504337 55.725947619008, -2.20305812201928 55.72522650644974, -2.203996544092868 55.725054232905165, -2.2058921238499467 55.7252487389968, -2.2156898178932316 55.72353372286023, -2.210662251491551 55.71525818426285, -2.211906263126429 55.71278513391512, -2.22365254334566 55.71009570101753, -2.2250778700345046 55.711647521522195, -2.2292366488446107 55.71114476823062, -2.232019815664577 55.71430776413941, -2.2324299366256586 55.714191025921906, -2.2351301025064467 55.71739023662485, -2.2356006128316306 55.717396216737896, -2.2368044264463682 55.71904716146524, -2.2395538780500144 55.72352539753981, -2.238537585670616 55.72394967742903, -2.2377941553157434 55.72474180996341, -2.2323875985406048 55.72582138605115, -2.2335894963323093 55.727130938742725, -2.2330567442951574 55.72856956832691, -2.234159338401812 55.729232367160705, -2.2404111584022304 55.73090049400845, -2.2445160998655225 55.730389218836784, -2.2466045795620597 55.73332316860523, -2.248359339262305 55.73381381096737, -2.2518505760586844 55.734408698791306, -2.2553978651407642 55.73381733763313, -2.257137364828705 55.73438875239554, -2.2639292218415994 55.73252578641048, -2.2655336789936817 55.73610705868756, -2.2702755134292585 55.734671430078414, -2.2709529685316796 55.73453016433232, -2.2700764579298673 55.73331216128484, -2.2707878291859243 55.732553392198234, -2.274808252207637 55.73137639318574, -2.274032987766631 55.72981471710219, -2.2795676006070273 55.72891271011806, -2.2796839887042974 55.72960429877977, -2.281304647338783 55.72912438434379, -2.283297118225879 55.72942529594496, -2.2857342340444 55.7317378065403, -2.288586246219992 55.731973732924416, -2.290429281318551 55.73142129440207, -2.292204725035964 55.73248630960454, -2.2948083024887405 55.7314378113796, -2.3014782258388293 55.7311879991755, -2.3028740078119254 55.730483724173226, -2.3056070713450385 55.72975814105231, -2.304464062865153 55.72815264441364, -2.304285428170114 55.72770383117027, -2.3016992621039543 55.72475410838433, -2.3052257007105577 55.72373905583538, -2.3030583466228944 55.72139930687901, -2.3102205411353434 55.721219681974624, -2.3085974421349174 55.72331730937581, -2.3166884592596286 55.7296671584131, -2.315173341952928 55.73331003183628, -2.319181781649966 55.73861886470775, -2.318611307408389 55.738970774773634, -2.3150521483690363 55.741980976462294, -2.315968065991472 55.74297596959661, -2.3185600649326923 55.74440688889258, -2.319560015614042 55.74397300555128, -2.3260661853452693 55.74294956866598, -2.328305260427504 55.742143927585516, -2.3365056922091867 55.749273873514696, -2.3367828569634876 55.75000989206574, -2.338765907269866 55.749052016708944, -2.3390973974141183 55.74870068274688, -2.3433866337851335 55.7473409977976, -2.3462312198260005 55.74836630691835, -2.3478713395817197 55.75007781813037, -2.3492916432798543 55.75035232490326, -2.352396731055199 55.750190707244485, -2.3534418888472994 55.75125693133744, -2.355699712337986 55.75426940756895, -2.3574165236353237 55.75384212347513, -2.358905467070718 55.75636259488732, -2.3528795094056294 55.75778173144988, -2.3487289364835418 55.75870108098699, -2.3468328697915846 55.75871543502199, -2.3476583823216712 55.760159700785685, -2.3503681500762545 55.76025083673786, -2.352970026249422 55.76074655219321, -2.354011263353423 55.76134555663048, -2.3540981086060246 55.76213599423465, -2.3557136399417953 55.762796222874194, -2.3550643630007246 55.76324735589922, -2.35567262589782 55.76354210400625, -2.3562527147753887 55.76424125077933, -2.356096466260582 55.76458314614389, -2.356835862926674 55.76527285204256, -2.356984797105324 55.76587442003266, -2.356753132459287 55.76668375068939, -2.3560715185372247 55.767090057162484, -2.3561418253497526 55.76780866893413, -2.3569725575214773 55.7680218905898, -2.35970971714266 55.76756465167982, -2.362491868315692 55.768526862253964, -2.36231082150405 55.76979401444153, -2.362020206406151 55.770215049559845, -2.360069305243987 55.77068139451072, -2.359567587984067 55.77116807629862, -2.355553588310837 55.772214058861955, -2.3519863026203347 55.768845448981914, -2.3486690752956 55.769842755855784, -2.346991118017659 55.76823429944648, -2.3469410199289205 55.76550785547327, -2.345114986893585 55.76266472806449, -2.3438041517392754 55.76220117977698, -2.3411245635992253 55.763754085514755, -2.3362243747412386 55.76471103042837, -2.3357213046616128 55.76366115209321, -2.3318076633001796 55.76445348889266, -2.3334998020588125 55.76665025002141, -2.329268368490576 55.76759611375997, -2.328666141421151 55.76800205492637, -2.331984068000433 55.770203459853334, -2.3325262140946452 55.7702289486292, -2.333845699686711 55.7716899359668, -2.3354229363661076 55.7715957886152, -2.3358088030664423 55.77198109234121, -2.335382348747556 55.77269337164396, -2.3354685605904604 55.77319500615932, -2.334098725829101 55.7733155452699, -2.3321768694184897 55.77412941307746, -2.3317305403812685 55.77413061917969, -2.3315773202499597 55.77485882301489, -2.330606760250241 55.774972548189375, -2.3295400268941053 55.775358690238086, -2.3293424590930476 55.775646679147755, -2.33085342842227 55.77693899256537, -2.3317412543829024 55.777266376909914, -2.3299185284776747 55.77852020862967, -2.330510441552894 55.778761214139344, -2.3327673541495253 55.77733868986867, -2.334830165987707 55.77824129475081, -2.3367044819028546 55.7773843792555, -2.3378169999449137 55.777152816949325, -2.34011521019903 55.77777359714449, -2.340629896468368 55.77829330472394, -2.340122258186235 55.77858223314566, -2.340747374741098 55.77896685849868, -2.339859849862865 55.77957131593932, -2.339104056266104 55.780660596450474, -2.337456321366434 55.78186014588654, -2.337728915777359 55.782039097937805, -2.336398876657829 55.783111968322494, -2.336990356081483 55.7832900484338, -2.3364058490885413 55.78392060392688, -2.3349399979945717 55.78590131977504, -2.3355378500837336 55.78681616337387, -2.336439709170608 55.787846977497715, -2.333989791340505 55.788527539890914, -2.333490696617269 55.78797182281829, -2.33229560649615 55.788073896271506, -2.3285069013435438 55.78884781315449, -2.3312834603920005 55.79282073075659, -2.332716936671835 55.79260121668033, -2.3328153075600926 55.79478431403288, -2.330150571592098 55.794638757030704, -2.33017772938015 55.7978463402786, -2.327944954018994 55.79787927442418, -2.3249376606023433 55.798758811046554, -2.325025201814186 55.799693022167425, -2.3242673359510153 55.80062946683454, -2.322242281059005 55.80072464404952, -2.3218778512744405 55.80102210487886, -2.325043852936576 55.80193024356999, -2.3280760340663367 55.802083916346845, -2.3291900768792586 55.80177544637733, -2.3309852870316417 55.80090806201088, -2.333119070982101 55.800471015143586, -2.3338272265536575 55.801205865591456, -2.3331742210102355 55.80297305116624, -2.333916492500739 55.805148772077914, -2.334205633046164 55.80570165199966, -2.3352299877221947 55.80655207947876, -2.338393337743761 55.807980411047055, -2.3393680034813027 55.807685827318814, -2.3381527455302904 55.80720638504148, -2.3392993327448104 55.80676537599417, -2.339997876598406 55.80609920094827, -2.3410203163301513 55.80441542329743, -2.3417637837845775 55.80370830321359, -2.344353530732749 55.80364382147367, -2.3454602446030237 55.80404073781862, -2.3468356856971333 55.804856235198734, -2.3557152816731852 55.806697207058534, -2.3586199083724075 55.806805571398506, -2.36199263038871 55.80749651610666, -2.3666229956164178 55.8095763024674, -2.3681147627982866 55.8104164270897, -2.367377830602828 55.811793349383194, -2.3623517980119733 55.81180826878018, -2.3609678986957348 55.81227057668848, -2.3654124704230655 55.81320087096997, -2.367468705941334 55.812970115471, -2.3660738436608386 55.81566079780568, -2.3652463409985183 55.815905854809316, -2.3662073273520976 55.81628036625188, -2.367727764319928 55.81844121553825, -2.3680788461300977 55.82012934686929, -2.3661338647900356 55.82204896179293, -2.365464447491205 55.82384795463902, -2.3632439551815447 55.82535503091387, -2.360457809572908 55.82612695644556, -2.3591189460035498 55.82633752966263, -2.3567084119615864 55.826308607512466, -2.3563119373051546 55.824845202665934, -2.3549499297925096 55.82426511781426, -2.3511732987732312 55.824949829954285, -2.347292676275374 55.82472725318924, -2.3445971141568633 55.824941502616156, -2.344463927523079 55.82432190226638, -2.3432851229543274 55.824585764557064, -2.339076206944712 55.82514553041695, -2.336842653414643 55.82526846673447, -2.3341379547663825 55.82629116090486, -2.3316021948866053 55.82654960678089, -2.329134044745214 55.82725706863145, -2.3293643512840863 55.82806510046308, -2.328797029046297 55.830825008686965, -2.3315595036876724 55.83278530005797, -2.332172048526871 55.833475489893644, -2.3322116427968056 55.834373880598264, -2.332950716941411 55.834919964866216, -2.3353020075419675 55.83542571853928, -2.3368603653638087 55.83654458068184, -2.3377247126978666 55.83863570830262, -2.339442861863908 55.83974511347167, -2.338982552716618 55.840060857333896, -2.338424444865447 55.841985177997024, -2.338422268221455 55.84540845552266, -2.337108318898321 55.84674183888282, -2.335292225962687 55.84726793176842, -2.333759237329175 55.84729007205212, -2.331247702410248 55.84680269054733, -2.332113481968984 55.84532682198251, -2.32859678995674 55.844931946759324, -2.320929092641731 55.84078317699307, -2.3191520482914085 55.84022174987965, -2.317508214819464 55.84032484046412, -2.3130418882550594 55.84288802163206, -2.311342833822972 55.842092674466336, -2.3009529967862425 55.84695244896063, -2.2964939884112305 55.84442952670294, -2.2937670997090245 55.84705967692917, -2.2851007568404302 55.85000915927182, -2.2820285592811937 55.84923456378896, -2.277667503204611 55.84687246575909, -2.274257864198157 55.845748016295914, -2.2707037306265447 55.84448003155664, -2.275277543934783 55.843149088632664, -2.274173619337982 55.84285505226426, -2.2773799606820178 55.84238063367469, -2.2745047757547106 55.839997099769725, -2.2753773225527034 55.83919548770304, -2.2765615626690745 55.83957020622796, -2.2815371435725083 55.83870533277524, -2.2801174530899364 55.83667797594458, -2.280866038982606 55.83642468911436, -2.2815645084933522 55.835866023929114, -2.2827131864581562 55.8357465831478, -2.2808816266731067 55.83291551451974, -2.2792827560792115 55.83383164321293, -2.278958760534366 55.83317647672795, -2.274207715862887 55.834094647591684, -2.2662770144315827 55.834678135144266, -2.2664575509077554 55.83539654036081, -2.2635784018914604 55.83580371023022, -2.2633595522798773 55.83555982450505, -2.259801685757456 55.83567135160611, -2.257906317134888 55.83395023191556, -2.253692522141897 55.83410275142213, -2.25121737380135 55.83401799456558, -2.244102591772599 55.83492184039829, -2.2410412569336073 55.83299611774093, -2.2369728140421126 55.83079372204446, -2.236596641653867 55.829311938181235, -2.2343439635653497 55.82900178081031, -2.2307954078388685 55.82819985011124, -2.2283270033395324 55.826470364312684, -2.2238601092536463 55.826900875660684, -2.2143624094027032 55.829766040723065, -2.2141740142727477 55.83034140601566, -2.206511693021752 55.830381476616516, -2.2074451881729695 55.831808510838215, -2.201540109311529 55.83213281076201, -2.2015449477850915 55.83306723696055, -2.2025797287500835 55.8355723340308, -2.2010331524880526 55.83597919609536, -2.197917174018151 55.835463127728374, -2.1977403657390475 55.835229803962264, -2.190027544485803 55.834936485674035, -2.1869464281244877 55.834986136741804, -2.185979460481168 55.83309178213616, -2.1831673198000043 55.83259284995598, -2.1796070478360416 55.83255318139564, -2.1784907348371783 55.83281536247568, -2.1763156536374115 55.83195596699167, -2.1745757617846766 55.83200336736248, -2.174175330220144 55.83170742372858, -2.1716591916583687 55.833112624565445, -2.1687937416565455 55.83500343138487, -2.1612283304167823 55.83554370415862, -2.15784405171033 55.83565591843915, -2.1551900195934297 55.83472486718876, -2.153558827199811 55.834035077392265, -2.1519627454648824 55.83414488154156, -2.153395634348024 55.8331367879447, -2.157297422283733 55.83076881513982, -2.1534576677334383 55.82862627183527, -2.1586595937009134 55.82422602452006, -2.1525046057802926 55.821682095823824, -2.151758044504402 55.82259948552947, -2.1501606738137413 55.82225103599086, -2.149064781097665 55.8194850149832, -2.152158593132544 55.81890617457506, -2.1537217267558857 55.81869757393017, -2.1536212389538845 55.817493715526005, -2.152510861821712 55.815132055361204, -2.14827879149105 55.8142477274541, -2.1452633670979426 55.81436813626359, -2.1434912809066664 55.81413661096927, -2.1412072620256932 55.81353726657687, -2.138110684364319 55.813262255108235, -2.134564450765869 55.81214307298408, -2.1195899956187896 55.81486304735625, -2.0987286145607897 55.8190775760955, -2.0933886927481025 55.82171434612332, -2.092334605990999 55.82140965594017, -2.0902946609404895 55.82266906642674, -2.088525142308435 55.823586820188844, -2.0851119732982117 55.82470336854435, -2.0843785947781814 55.8250902276088, -2.0827983039918556 55.825046379963496, -2.0752432018200233 55.83051408789378, -2.0736941841764804 55.83022750200988, -2.0721334886479226 55.83089519278872, -2.071727386235796 55.83054989767272, -2.0692509815102262 55.83070558391247, -2.0645678407591985 55.82845594219568, -2.061990973882655 55.82902102349776, -2.0613897165506394 55.8282983627774, -2.0615587126613497 55.82600259166018, -2.05709257150354 55.826557301216305, -2.0548938711442286 55.826932996226084, -2.054457539842128 55.82980629339027, -2.0543525287751696 55.829887667128716)))
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>