简体   繁体   中英

Cypher Query and AgensGraph

The following query only returns vlabel.

Should it return elabls as well?

match 
return distinct labels;

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM