Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I return all properties for a node using Cypher?

Tags:

I understand it is possible to use the wildcard (*) symbol to return all references in a Cypher query, such as:

MATCH p:Product WHERE p.price='1950' RETURN *;    ==> +----------------------------------------------------------------+   ==> | p                                                              |   ==> +----------------------------------------------------------------+   ==> | Node[686]{title:"Giorgio Armani Briefcase",price:"1950",...    |   ==> +----------------------------------------------------------------+ 

However, the result is a row with a single node 'column' named "p", from which the properties can be accessed. However, I'd like the result-set 'rows' to have the property names as 'columns'. Something like:

MATCH p:Product WHERE p.price='1950' RETURN p.*;    ==> +-------------------------------------------+   ==> | title | price | ...                       |   ==> +-------------------------------------------+   ==> | "Giorgio Armani Briefcase" | "1950" | ... |   ==> +-------------------------------------------+ 

That particular query isn't valid, but is there a way to achieve the same result (short of listing all the properties explicitly, as in p.title,p.price,p... )?

like image 529
DavidJ Avatar asked Jul 18 '13 22:07

DavidJ


People also ask

How do I return all nodes and relationships in Neo4j?

When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. This returns the two nodes, the relationship and the path used in the query.

What does unwind do in Cypher?

Essentially, UNWIND [] reduces the number of rows to zero, and thus causes the query to cease its execution, returning no results.

What is the syntax for getting all the nodes under specific label in Neo4j?

If you want to get the labels of a specify node, then use labels(node) ; If you only want to get all node labels in neo4j, then use this function instead: call db. labels; , never ever use this query: MATCH n RETURN DISTINCT LABELS(n) . It will do a full table scan, which is very very slow..

How do you write a Cypher query?

Cypher uses an ASCII-art type of syntax where (nodes)-[:ARE_CONNECTED_TO]->(otherNodes) using rounded brackets for circular (nodes) , and -[:ARROWS]-> for relationships. When you write a query, you draw a graph pattern through your data.


1 Answers

You can't do this in Cypher yet. I think it would be a nice feature though, if you want to request it.

Edit (thanks for comment pointing it out): You can now do this as of 2.2:

MATCH (p:Product) WHERE p.price='1950' RETURN keys(p); 
like image 152
Eve Freeman Avatar answered Oct 21 '22 22:10

Eve Freeman