GROUP_CONCAT

The GROUP_CONCAT function performs a string concatenation of all of the values that are bound to the given variable.

GROUP_CONCAT Syntax

Use the following syntax when incorporating the GROUP_CONCAT function in a query. The table below describes each of the GROUP_CONCAT options.

GROUP_CONCAT (expression ; [ SEPARATOR = "value" ] ; [ ROW_LIMIT = integer ] ;
[ PRE = "string" ] ; [ VALUE_SERIALIZE = boolean ] ; [ DELIMIT_BLANKS = boolean ] ; [ MAX_LENGTH = integer ] ; [ SUFFIX = "string" ])
Option Description
SEPARATOR = "value" This option defines the separator to use between the values in the returned strings. When SEPARATOR is omitted, AnzoGraph separates values with a space.
ROW_LIMIT = integer This option limits the number of values that are concatenated. When ROW_LIMIT is omitted, the default value is unlimited.
PRE = "string" This option defines a prefix to add to the resulting concatenated strings. When PRE is omitted, AnzoGraph does not add a prefix (the default value is an empty string).
VALUE_SERIALIZE = boolean This option indicates whether returned values should be serialized with the value's data type. When VALUE_SERIALIZE is omitted, the default value is false.
DELIMIT_BLANKS = boolean This option indicates whether to delimit blanks with the SEPARATOR value. When DELIMIT_BLANKS is omitted, the default value is false.
MAX_LENGTH = integer This option limits the strings that GROUP_CONCAT creates to a maximum character length. AnzoGraph has a 1MB (1000000) limit on the length of strings and displays an error if GROUP_CONCAT returns a string that is longer than 1000000. The default MAX_LENGTH value is unlimited.
SUFFIX = "string" This option defines a suffix to add to the resulting concatenated strings. When SUFFIX is omitted, AnzoGraph adds an empty string as the suffix.

Note: A GROUP BY statement is required for queries that contain GROUP_CONCAT functions if the results clause lists non-aggregate variables. Include all non-aggregated variables in the GROUP BY statement.

GROUP_CONCAT Examples

The example queries in this section run against the AnzoGraph sample Tickit data set, which captures sales activity for a fictional Tickit website where people buy and sell tickets for sporting events, shows, and concerts. You can load and explore this data set. For more information, see Working with the Tickit Data.

The example query below uses the GROUP_CONCAT function to concatenate the list of friends for 100 people in the sample Tickit data set. Since the GROUP_CONCAT expression includes ROW_LIMIT=10, AnzoGraph concatenates 10 friends for each person.

SELECT ?person (GROUP_CONCAT(?friend;SEPARATOR=",";ROW_LIMIT=10) AS ?friends)
FROM <tickit>
WHERE { 
  ?person <friend> ?friend .
}
GROUP BY ?person
ORDER BY ?person
LIMIT 10
 person      | friends
-------------+----------------------------------------------------
 person1     | person12081,person32204,person28342,person12316,pe
 person10    | person45403,person2612,person36152,person5951,pers
 person100   | person16258,person28322,person6322,person24406,per
 person1000  | person19040,person41993,person41100,person18154,pe
 person10000 | person47062,person12859,person38684,person43369,pe
 person10001 | person7253,person31442,person28728,person10397,per
 person10002 | person39772,person9153,person22097,person46441,per
 person10003 | person2134,person6960,person31356,person48947,pers
 person10004 | person25750,person1804,person21205,person11070,per
 person10005 | person41966,person16941,person5137,person43483,per
10 rows