How can I return all properties for a node using C

2019-01-26 04:21发布

问题:

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... )?

回答1:

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);


回答2:

In the latest version of cypher properties(n) will return all the keys and properties of a node. Seems to only work for a single node though.

I hope this helps people.



回答3:

Just to expand on getting the keys:

MATCH (p:product) WITH DISTINCT keys(p) AS keys
UNWIND keys AS keyslisting WITH DISTINCT keyslisting AS allfields
RETURN allfields;


回答4:

You can return n in your cypher query, it will return all the keys and properties of a node. eg.: MATCH (n:People) n
This will return
n:
{ "Date_of_Birth": "1981-04-23 00:00:00", "Employee_Last_Name": "Aaaa", "Employee_First_Name": "Baaa", "Age": 36, "Employee_Status": "Active" }



回答5:

You can use the 'as' clause and identify each property and what you want the column to be named. You will have to identify each property you want returned individually though.

ex:

MATCH p.product where WHERE p.price='1950' RETURN p.price as price, p.title as title, p.whatever, as anythingYouWant


回答6:

I'm new to cypher, but it seems that this returns all the keys for a particular type of node:

MATCH (p:product) RETURN keys(p)

Works in Neo4J 3.0.