postgresql 在ApacheAGE扩展中,Cypher()函数可以接受哪些参数?

iecba09b  于 2023-03-08  发布在  PostgreSQL
关注(0)|答案(1)|浏览(153)

在阅读了文档之后,我没有发现如果提供了NULL参数,Cypher()函数会做什么。根据我的理解,如果有一个正确准备的语句,它应该执行该语句。这是正确的吗?也是在什么图上?因为在某些情况下,“graph_name”参数也是NULL。

jdzmm42g

jdzmm42g1#

cypher函数语法如下所示:

SELECT * FROM cypher('graph_name', $$ 
/* Cypher Query Here */ 
$$) AS (result1 agtype, result2 agtype);

因此,有必要将图形的名称作为第一个参数传递,并将查询作为第二个参数传递(注意,查询的开头和结尾必须有两个美元符号)。如果未传递这些参数,则会发生错误,因为函数将无法标识其正在处理的列和名称空间。以下是一些错误示例:

-- Inserting nothing
SELECT * FROM cypher() as (a agtype);
server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

-- Not inserting the double dollar signs
SELECT * FROM cypher('graph_name') as (a agtype);
server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.                ^

-- Not passing the query correctly
SELECT * FROM cypher('graph_name', $$$$) as (a agtype);
ERROR:  syntax error at end of input
LINE 1: SELECT * FROM cypher('graph_name', $$$$) as (a agtype);

documentation还指出,我们需要考虑两件事:

  • 如果密码查询不返回结果,则仍然需要定义记录定义。
  • 参数Map只能与预准备语句一起使用。否则将引发错误。

第一点意味着,如果查询没有返回结果(例如,试图返回不属于顶点或边的属性),则在返回查询时仍然需要显示表结构,即使它是空的。

相关问题