首页 文章

Neo4J Cypher数据类型转换

提问于
浏览
12

我在我们的 Product -nodes上有一个属性 quantity ,我正在寻找一个cypher查询,它给我所有节点 quantity = 20 ...问题是数量在neo4j中存储为一个字符串 . 有没有办法在cypher查询中将属性强制转换为整数?

// This fails to find the required nodes
MATCH (p:Product) WHERE p.quantity = 20;

// This finds them
MATCH (p:Product) WHERE p.quantity = "20";

// I would like to do this
MATCH (p:Product) WHERE INT(p.quantity) = 20;

PS:这是一个非常简化的用例,我们实际上没有产品和数量,但只是面对现有的neo4j数据,其中整数值存储为字符串,我们想对这些字符串进行一些匹配

3 回答

  • 0

    你可以反过来做 .

    MATCH (p:Product) WHERE p.quantity = str(20) RETURN p;
    

    也应该与params一起使用 .

    MATCH (p:Product) WHERE p.quantity = str({quantity}) RETURN p;
    

    甚至是内联属性匹配

    MATCH (p:Product {quantity : str({quantity})}) RETURN p;
    
  • 7
    MATCH (p:Product) WHERE toInt(p.quantity) = 20;
    
  • 9

    我之前也遇到过这个问题 . 据我所知,在cypher中直接进行转换是不可能的 . 我使用一个小的Java脚本(使用标准Java API)来更改存储值的数据类型 . 这是几个月前,所以它可能已经改变了2.0版本 .

相关问题