cypher - How to get null for labels that don't exist in Neo4J? -


i'm running following query in neo4j , i'm getting error. in nutshell, i'm asking database show me nodes label "user" and, if has relationship, type of relationship , label type of node it's connected to.

start n=node(*) match (n:user)-[r?]-(m) has (n.name) return n, labels(n), type(r), labels(m), m.name; 

an error occurs when node of type user found doesn't have node related it. seems blowing on labels(m) part. expect if node didn't exist, null returned instead of error. how type() function works. if no relationship found, type() returns null.

here result looks if omit labels(m) part...

==>+-----------------------------------------------------------------------------------------------------------------------------------+ ==> | n                                                                                    | labels(n) | type(r)      | m.name          | ==> +-----------------------------------------------------------------------------------------------------------------------------------+ ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"} | ["user"]  | "hascontext" | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"} | ["user"]  | "hascontext" | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"} | ["user"]  | "hascontext" | "vinniecontext" | ==> | node[2558]{lastname:"b",mobilephone:"b",status:"b",email:"b",name:"b",firstname:"b"} | ["user"]  | <null>       | <null>          | ==> | node[2559]{lastname:"c",mobilephone:"c",status:"c",email:"c",name:"c",firstname:"c"} | ["user"]  | <null>       | <null>          | ==> | node[2560]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"} | ["user"]  | <null>       | <null>          | ==> | node[2561]{lastname:"b",mobilephone:"b",status:"b",email:"b",name:"",firstname:"b"}  | ["user"]  | <null>       | <null>          | ==> +-----------------------------------------------------------------------------------------------------------------------------------+  

how can result want? want null value in case there no connecting node, otherwise give me label of connecting node.

thanks in advance!!

ok coworker helped me solve problem (after pounded head against desk day , half). got results wanted using union all. have 2 different queries; 1 relationships null , 1 relationships not null.

start n=node(*) match (n:user)-[r?]-(m) r not null return n, labels(n), type(r), labels(m) i, m.name  union start n=node(*) match (n:user)-[r?]-(m) r null return n, labels(n), type(r), null i, null a; 

and here's result...

==> +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ ==> | n                                                                                                                                               | labels(n) | type(r)      |           |               | ==> +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | "hascontext" | ["context"] | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | "hascontext" | ["context"] | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | "hascontext" | ["context"] | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | "hascontext" | ["context"] | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | "hascontext" | ["context"] | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | "hascontext" | ["context"] | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | "hascontext" | ["context"] | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | "hascontext" | ["context"] | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | "hascontext" | ["context"] | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | "hascontext" | ["context"] | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | "hascontext" | ["context"] | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | "hascontext" | ["context"] | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | "hascontext" | ["context"] | "vinniecontext" | ==> | node[2557]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | "hascontext" | ["context"] | "vinniecontext" | ==> | node[2558]{lastname:"b",mobilephone:"b",status:"b",email:"b",name:"b",firstname:"b"}                                                            | ["user"]  | <null>       | <null>      | <null>          | ==> | node[2559]{lastname:"c",mobilephone:"c",status:"c",email:"c",name:"c",firstname:"c"}                                                            | ["user"]  | <null>       | <null>      | <null>          | ==> | node[2560]{lastname:"a",mobilephone:"a",status:"a",email:"a",name:"a",firstname:"a"}                                                            | ["user"]  | <null>       | <null>      | <null>          | ==> | node[2561]{lastname:"b",mobilephone:"b",status:"b",email:"b",name:"",firstname:"b"}                                                             | ["user"]  | <null>       | <null>      | <null>          | ==> | node[7638]{lastname:"afdasdfasdf",mobilephone:"asdfa",status:"asdfasdf",email:"asdfasdfasdf",name:"asdfasdfa",firstname:"asdfasdfas"}           | ["user"]  | <null>       | <null>      | <null>          | ==> | node[7639]{lastname:"asddsafsda",mobilephone:"asdfasdfdsa",status:"sadfsadfsda",email:"sadfasdfas",name:"sdafasdfsadf",firstname:"sadfsadfsad"} | ["user"]  | <null>       | <null>      | <null>          | ==> +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+  

i hope solution saves else pain.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -