1

I'm working with a Wikidata query:

SELECT DISTINCT ?protected_area ?protected_areaLabel ?coordinate_location ?territorialEntity ?territorialEntityLabel (SAMPLE(?instance_of) AS ?instance_of) ?instance_ofLabel WHERE {
  {
    ?prop wdt:P31 wd:Q55978235;
      wikibase:directClaim ?claim.
    ?protected_area ?claim _:b1;
      wdt:P625 ?coordinate_location.
    OPTIONAL { ?protected_area wdt:P31 ?instance_of. }
    OPTIONAL { ?protected_area wdt:P131 ?territorialEntity. }
  }
  UNION
  {
    ?protected_area (wdt:P31/(wdt:P279*)) wd:Q473972;
      wdt:P625 ?coordinate_location.
    OPTIONAL { ?protected_area wdt:P31 ?instance_of. }
    OPTIONAL { ?protected_area wdt:P131 ?territorialEntity. }
  }
  #    SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }

}

This gives a "Query is malformed: Bad aggregate" error.

Before using SAMPLE the query worked.

After some reading I considered the SAMPLE keyword would require grouping, so tried this:

SELECT DISTINCT ?protected_area ?protected_areaLabel ?coordinate_location ?territorialEntity ?territorialEntityLabel (SAMPLE(?instance_of) AS ?instance_of) ?instance_ofLabel WHERE {
  {
    ?prop wdt:P31 wd:Q55978235;
      wikibase:directClaim ?claim.
    ?protected_area ?claim _:b1;
      wdt:P625 ?coordinate_location.
    OPTIONAL { ?protected_area wdt:P31 ?instance_of. }
    OPTIONAL { ?protected_area wdt:P131 ?territorialEntity. }
  }
  UNION
  {
    ?protected_area (wdt:P31/(wdt:P279*)) wd:Q473972;
      wdt:P625 ?coordinate_location.
    OPTIONAL { ?protected_area wdt:P31 ?instance_of. }
    OPTIONAL { ?protected_area wdt:P131 ?territorialEntity. }
  }
  #    SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }

}
GROUP BY ?protected_area ?protected_areaLabel

And again the same "Query is malformed: Bad aggregate" error.

I really don't know how to diagnose and obviously to fix it :-|

  • SAMPLE still requires grouping. – Stanislav Kralin May 28 at 15:16
  • But in the second try I'm using grouping and still get same error. I tried other group combinations but still the same. Seems I'm missing something obvious :-m – Ismael Olea May 28 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.