- From: Steve Harris <steve.harris@garlik.com>
- Date: Tue, 20 Oct 2009 18:54:22 +0100
- To: "public-rdf-dawg@w3.org Group" <public-rdf-dawg@w3.org>
GROUP_CONCAT() is an aggregate function that takes an aggregated
variable, and returns a string - I guess a plain literal in RDF terms.
What it does it build a sting from all the aggregate values joined
with some separator.
NULLs are removed from the values.
Example
data:
<> :a "foo", "bar", "baz" .
query:
SELECT GROUP_CONCAT(?y, "|") AS ?cat
WHERE {
?x :a ?y .
} ORDER BY ?y GROUP BY ?x
results:
?cat = "bar|baz|foo"
This is very useful if for example you want to display all of
someone's names in FOAF:
SELECT ?person, GROUP_CONCAT(?name, ", ") AS ?names
WHERE {
?person foaf:mbox_sha1sum
"efd5dda12dd4011bb051b5f294ec05f2a8c87e21" .
?person foaf:name ?name .
} GROUP BY ?person
As Andy said on the call, if you want the output to be machine
readable (e.g. to treat it as an array on the client side) you may
need to escape the values passed to GROUP_CONCAT.
- Steve
Received on Tuesday, 20 October 2009 17:54:54 UTC