2

The following query only returns vlabel.

Should it return elabls as well?

match 
return distinct labels;
Eya
  • 121
  • 4
  • While running some queries (on 2.1.3) I found that the `label()` function works for both vertexes and edges, though it seems to return the label as a string, differently from `labels()` that returns an array. – watery Mar 09 '21 at 22:04

1 Answers1

0

According to the docs in the "List functions" section, the labels() function will only return vlabels.

labels()
Returns vlabel of the vertex passed as an argument. You should be careful when passing arguments to the label function; when you find a vertex that matches the pattern using MATCH clause, assign a variable, and pass that variable as an argument, the vertex itself cannot be passed as an argument to the label function, but must always be passed as a variable.

If you wanted the edges/relationships, the docs state to use the relationships() function:

relationships()
Returns the edges present in the path passed as an argument. You should be careful when passing arguments to the relationships function; when you find a path that matches the pattern using MATCH clause, assign a variable, and pass that variable as an argument, the path itself cannot be passed as an argument to the relationships function, but must always be passed as variable. When used with the count function, the number of edges in the path can be found.

Therefore, to list both vlabels and elabels, you would want something like the following query (note we assign the resulting path to p which gets passed to the relationships function):

MATCH p=(n)-[r]->(m)
RETURN DISTINCT labels(n), relationships(p), labels(m);

-- Example results
  labels  |               relationships               |  labels
----------+-------------------------------------------+----------
 ["part"] | [used_by[19.3][18.4,18.5]{"quantity": 1}] | ["part"]
 ["part"] | [used_by[19.4][18.5,18.6]{"quantity": 2}] | ["part"]
 ["part"] | [used_by[19.5][18.4,18.7]{"quantity": 1}] | ["part"]
(3 rows)
sorrell
  • 1,801
  • 1
  • 16
  • 27