PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, June 28, 2022

[FIXED] How to match a square bracket in Neo4j while doing a graph query?

 June 28, 2022     cypher, graph, neo4j     No comments   

Issue

I am trying to match a graph object which has a code property of such "code": ["DAF AR Index"].

The query match (n:GenericProduct {code:["DAF AR Index"]}) return n; works as expected and the object is returned, but I have been unable to match the object either using CONTAINS or a regular expression. To match a single opening bracket, I have tried

match (n:GenericProduct)
where  n.code =~ '\[.*'
    return n;

the same expression with double backslashes - n.code =~ '\\[.*', and finally with

match (n:GenericProduct)
where  n.code contains '['
    return n;

but so far without success. Any advice on how to proceed would be appreciated. Thanks in advance.


Solution

There are two ways you can find nodes that have a specific property stored as a list:

Using APOC procedures:

MATCH (n:GenericProduct)
WHERE apoc.meta.cypher.type(n.code) = "LIST OF STRING"
RETURN n

Or using a "hacky" cypher:

MATCH (n:GenericProduct)
WHERE size(n.code + 11) = size(n.code) + 1 
RETURN n


Answered By - Tomaž Bratanič
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing