The ADD_ELEMENT
row function adds an element to a set.
ADD_ELEMENT
takes an atomic value and a set and returns that set with the atomic value added to it. The atomic value must be of the same data type as the current elements in the set. The atomic value is not added to the set if a duplicate value is already in the set. Note that the atomic value is not added to the set in the Dgraph, but only to the new, temporary set that is created by the ADD_ELEMENT
function.
ADD_ELEMENT
function is:
ADD_ELEMENT(<atomic-value>, <set>)
where:
{ }
indicates an empty set):
ADD_ELEMENT(1, { 2, 3 }) = { 1, 2, 3 } ADD_ELEMENT(1, { 1, 2 }) = { 1, 2 } ADD_ELEMENT(NULL, { 1, 2 }) = { 1, 2 } ADD_ELEMENT(1, { 'a', 'b' }) yields a checking error because the atomic value and the set elements are not of the same data type
ADD_ELEMENT example
RETURN results AS SELECT WineID AS idRec, ADD_ELEMENT(100, Score) AS addAttrs FROM WineState WHERE WineID BETWEEN 10 AND 14 ORDER BY idRec
addAttrs idRec ---------------------------- | { 100, 83, 85, 86 } | 10 | | { 100, 82, 83 } | 11 | | { 100, 81, 89 } | 12 | | { 100, 73, 75 } | 13 | | { 100, 72, 74, 75 } | 14 | ----------------------------
The results show that the number 100 was added to the sets. For example, the Score set of Record 12 previously had 81 and 89 as its elements, but now has 81, 89, and 100 as the element values.