query-30dc8634c034b2178ad36aa6c67ef2a0

rq turtle/ttl

But as soon as there are no P150, the script gets a timeout. I tried BIND(if(bound(?ortsteileTmp), ?ortsteileTmp, ?o_tmp) AS ?ortsteile) but I can't figure out how to get wdt:P625 here. How can I only pull wdt:P625 if there are wdt:P150? Thanks! Not sure quickly how to find an item without a P150, but the answer is probably this - a nested pair of optionals.

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?ort ?ortLabel ?wappen ?coord ?ortsteile ?ortsteileLabel ?ortsteileLatLng
    WHERE
    {
      ?ort wdt:P439 '02000000'. #HH: 02000000. WGT:08215090, Stutensee:08215109, Berlin:11000000
      OPTIONAL{?ort wdt:P94 ?wappen .}
      OPTIONAL{?ort wdt:P625 ?coord .}
      OPTIONAL{?ort wdt:P150 ?ortsteile .
      OPTIONAL{?ortsteile wdt:P625 ?ortsteileLatLng .} }
      #BIND(if(bound(?ortsteileTmp), ?ortsteileTmp, ?o_tmp) AS ?ortsteile)

      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
    }

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?coord"):::projected v1("?ort"):::projected v4("?ortsteile"):::projected v5("?ortsteileLatLng"):::projected v2("?wappen"):::projected c2(["02000000"]):::literal c7(["bd:serviceParam"]):::iri c9(["#91;AUTO_LANGUAGE#93;"]):::literal v1 --"wdt:P439"--> c2 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v1 -."wdt:P94".-> v2 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v1 -."wdt:P625".-> v3 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v1 -."wdt:P150".-> v4 subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v4 -."wdt:P625".-> v5 end end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c7 --"wikibase:language"--> c9 end