Predicate function exists()存在。

huangapple go评论64阅读模式
英文:

Predicate function exists()

问题

Using the exists(expression) one can check for a property or path in a graph database. Looking at the example from the docs. You can use exists on properties as in exists(n.surname) and also on path. But from the example in the docs

SELECT * FROM cypher('graph_name', $$
 MATCH (n)
 WHERE exists(n)-[]-(name: 'Willem Defoe')
 RETURN n.full_name
$$) as (full_name agtype);

I’d expect the query to be

SELECT * FROM cypher('graph_name', $$
 MATCH (n)
 WHERE exists((n)-[]-(name: 'Willem Defoe')) 
 RETURN n.full_name 
$$) as (full_name agtype);

Since the syntax is exists(path). Also since the expression name: ‘Willem Defoe’ is a property I’d also expect that to be in curly braces thus the final query looks like this

SELECT * FROM cypher('graph_name', $$
 MATCH (n)
 WHERE exists((n)-[]-({name: 'Willem Defoe'})) 
 RETURN n.full_name 
$$) as (full_name agtype);

Or am I missing something?

英文:

Using the exists(expression) one can check for a property or path in a graph database. Looking at the example from the docs. You can use exists on properties as in exists(n.surname) and also on path. But from the example in the docs

SELECT * FROM cypher('graph_name', $$
 MATCH (n)
 WHERE exists(n)-[]-(name: 'Willem Defoe')
 RETURN n.full_name
$$) as (full_name agtype);

I’d expect the query to be

SELECT * FROM cypher('graph_name', $$
 MATCH (n)
 WHERE exists((n)-[]-(name: 'Willem Defoe')) 
 RETURN n.full_name 
$$) as (full_name agtype);

Since the syntax is exists(path). Also since the expression name: ‘Willem Defoe’ is a property I’d also expect that to be in curly braces thus the final query looks like this

SELECT * FROM cypher('graph_name', $$
 MATCH (n)
 WHERE exists((n)-[]-({name: 'Willem Defoe'})) 
 RETURN n.full_name 
$$) as (full_name agtype);

Or am I missing something?

答案1

得分: 1

是的,你说得对。文档中提供的查询存在语法错误,正确的查询应该是:

SELECT * FROM cypher('graph_name', $$
MATCH (n)
WHERE exists((n)-[]-({name: 'Willem Defoe'})) 
RETURN n.full_name 
$$) as (full_name agtype);

你可以在GitHub上提出问题这里

英文:

Yes, you are right. The query given in the documentation has a syntax error and the correct query as stated would be:

SELECT * FROM cypher('graph_name', $$
 MATCH (n)
 WHERE exists((n)-[]-({name: 'Willem Defoe'})) 
 RETURN n.full_name 
$$) as (full_name agtype);

You can raise an issue here on GitHub.

答案2

得分: 0

你建议的更正是正确的写法。如果运行第一个查询,将产生以下错误:

错误: 在“)”附近有语法错误
第3行:  WHERE exists(n)-[]-(name: 'Willem Defoe')
                       ^

类似地,第二个查询会产生以下错误:

错误: 在“'Willem Defoe'”附近有语法错误
第3行:  WHERE exists((n)-[]-(name: 'Willem Defoe'))
                                    ^

只有第三个查询成功解析并产生正确的输出。

英文:

The correction that you have suggested is how it should be written. If you run the first query, it will produce an error that says:

ERROR:  syntax error at or near ")"
LINE 3:  WHERE exists(n)-[]-(name: 'Willem Defoe')
                       ^

Similarly, the second query produces an error that says:

ERROR:  syntax error at or near "'Willem Defoe'"
LINE 3:  WHERE exists((n)-[]-(name: 'Willem Defoe'))
                                    ^

Only the third query successfully parses and produces a proper output.

答案3

得分: -1

你是绝对正确的,文档肯定有语法错误,你建议的查询应该是正确的。

英文:

You are absolutely correct, the documentation surely has syntax error and the query you suggested should be the correct one.

答案4

得分: -1

你说得对。EXISTS子句接受一个参数属性,该属性可以是一个顶点或路径,因此,在这个示例中,应该是这样的

WHERE exists((n)-[]-({name: 'Willem Defoe'}))
英文:

You are right. EXISTS clause take argument property which is a vertex or a path so, in this example it should be like this

WHERE exists((n)-[]-({name: 'Willem Defoe'}))

huangapple
  • 本文由 发表于 2023年5月21日 17:29:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76299181.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定