gpt4 book ai didi

Neo4J Cypher 数据类型转换

转载 作者:行者123 更新时间:2023-12-03 23:32:15 26 4
gpt4 key购买 nike

我有房产quantity在我们的 Product -nodes 并且我正在寻找一个密码查询,它为我提供所有节点 quantity = 20 ...问题是数量在neo4j中存储为字符串。有没有办法在密码查询中将属性转换为整数?

// 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数据,这些数据将整数值存储为字符串,我们想对这些字符串进行一些匹配

最佳答案

你可以反过来做。

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

也应该与参数一起工作。
MATCH (p:Product) WHERE p.quantity = str({quantity}) RETURN p;

甚至内联属性匹配
MATCH (p:Product {quantity : str({quantity})}) RETURN p;

关于Neo4J Cypher 数据类型转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21132844/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com