cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to RETURN node.* instead of RETURN node.prop1

clem
Graph Steward

If I want a traditional table of properties from a node, I know I can do:

RETURN n.prop1, n.prop2, n.prop, etc.

What I'd like to do is something like:
RETURN n.* to return all the property values (as a short hand).

I don't want RETURN n as it returns a Map, which is harder to for me to skim visually for patterns.

I've google what I want, and there are some close matches, but I haven't been able to find exactly what I want. I've also tried various permutations of UNWIND, keys() etc.

I realize this could be a mess if the nodes have radically dissimilar property names.... but my data is very regular. I'd be happy to use the keys() function on one node as the set of properties for all my nodes that I'm matching.

3 REPLIES 3

jhakiz
Node Link

@clem, if you need to retrieve only the properties of a node; something like RETURN n.*, you can try with RETURN properties(n) and see if it will meet your need.

it will return the keys of the node associated with their values.

Nope. That's not what I want.

If I do:
match(p:Person {name:"Ed Harris"}) return properties(p)

I get:

╒════════════════════════════════╕
│"properties(p)"                 │
╞════════════════════════════════╡
│{"born":1950,"name":"Ed Harris"}│
└────────────────────────────────┘

I want the equivalent of:

match(p:Person {name:"Ed Harris"}) return p.name, p.born

╒═══════════╤════════╕
│"p.name"   │"p.born"│
╞═══════════╪════════╡
│"Ed Harris"│1950    │
└───────────┴────────┘

but not having to manually enter all the property names.

Hi @clem,

There is no PIVOT functionality in neo4j. As an alternate solution I have created a python function, that can take any node name (or all if NONE provided).

Python jupyter notebook file -> neo4j_pivot.ipynb

Github URL -> neo4j/community/pivot_neo4j at master · dominicvivek06/neo4j · GitHub

Note - Try Exception not implemented in python as of now

The Cypher query to get key, value pair for the node is

MATCH (n) 
UNWIND keys(n) as property 
RETURN labels(n) as node,id(n) as node_id , property, n[property] as value;

Blog Post -> URL

Let me know how I can assist further.