Neo4J 在 Cypher 中创建临时变量 [英] Neo4J create temp variable within Cypher

查看:43
本文介绍了Neo4J 在 Cypher 中创建临时变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的顶级问题是我试图返回 MERGE 是否导致创建新节点.

So my Top-Level problem is I am trying to return whether a MERGE resulted in the creation of a new Node or not.

为了做到这一点,我想我可以创建一个简单的临时布尔值,使用 ON CREATE

In order to do this I was thinking I could just create a simple temp boolean setting it to TRUE using ON CREATE

我想象的它是如何工作的:

How I imagine it working:

MERGE(: Person {id:'Tom Jones'})
WITH false as temp_bool
ON CREATE set temp_bool = true
RETURN temp_bool

显然这是行不通的.

我正在寻找一种在 Cypher 查询中创建任意临时值的方法,并且能够最终返回这些变量.

I am looking for a way to create arbitrary temp values within a Cypher query, and have the ability to return those variables in the end.

谢谢

推荐答案

你可以为所欲为,方法如下(结合我的第一个答案,加上@cybersam 的补充).您只需使用您创建然后删除的节点属性来完成它,而不是像您一直在尝试的那样使用未绑定的变量.

You can do what you want, here's how (combination of my first answer, with @cybersam's addition). You just do it with a node property you create and then remove, instead of an unbound variable as you've been trying.

MERGE(tom:Person {id:'Tom Jones'})
ON CREATE set tom.temp_bool = true
ON MATCH set tom.temp_bool = false
WITH tom, tom.temp_bool AS result
REMOVE tom.temp_bool
RETURN result;

这篇关于Neo4J 在 Cypher 中创建临时变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆