I'm messing around with the idea of getting characteristic sets (a set of sets of properties used to describe the same subject) from RDF datasets using SPARQL 1.1. The idea is as follows:
SELECT ?characteristicSet
WHERE {
SELECT ?s (GROUP_CONCAT(?p; separator="|") as ?cs)
WHERE { ?s ?p ?o }
GROUP BY ?s
# ORDER BY ?p
}
I want to enforce an ordering in the GROUP_CONCAT
to ensure that subjects with the same property extension will produce the same string for ?cs. But the ORDER BY
shown won't work since, I assume, it is applied as a solution modifier after the SELECT
(i.e., effectively ignored).
Is there a way to enforce the ordering in GROUP_CONCAT
?
My searches tell me that SQL has a dedicated ORDER BY
clause that can be stuck in the brackets of GROUP_CONCAT
but the SPARQL 1.1 grammar tells me that ORDER BY
can only be a solution modifier. I also found the same question asked by @Jeen but without a resolution at that time.
(Another option might be to have another subselect sort all triples first, but that doesn't seem to guarantee that that ordering will hold later, plus it could be super super expensive.)