Search code examples
neo4jcypherneo4j-apoc

apoc refactor rename gives Procedure does not support implicit naming error


I try to write a cypher query that extracts a set of labels, that share one specific label. After is selected the labels i try to rename them. Which means add a prefix to each of the labels andrename the labels in the graph with help of apoc.refactor.rename.label. Therefore i wrote the following query.

match (c:TheLabel) 
with collect(distinct filter( l in labels(c) where not l in ["UNIQUE IMPORT LABEL","TheLabel"])[0]) as curr_label 
unwind curr_label as cl 
with cl as cl, "AR_"+cl as nl
call apoc.refactor.rename.label(cl, nl) 
return null

But this query fails with the following error message:

Neo.ClientError.Statement.SyntaxError: Procedure call inside a query does not support naming results implicitly (name explicitly using `YIELD` instead) (line 5, column 1 (offset: 214))
"call apoc.refactor.rename.label(cl, nl) return null"

I can't understand where i could use yield to get this query run. I tried the first part separately i.e. return nl & cl after the with. This works fine. I also tried to use the rename function with one specific cl and cl that i got while trying the first part of the query. That is also working fine. Only the combination seems not to work.

Edit:

I figured out that every unwind seems to break the query never the less if I use the variable that is defined by unwind or not. Minimal example that produces the same error:

unwind [1,2,3,4] as cl 
call apoc.refactor.rename.label("Test", "Test") 
return cl

Thanks in advance for any help or solutions.


Solution

  • If a procedure is defined to return any results, then the Cypher language requires that the CALL clause must be paired with a YIELD clause -- even if you don't care about any of the results. The only exception is when the entire Cypher statement consists of just a CALL clause (this is referred to in the docs as a "standalone procedure call").

    To quote from the docs:

    If the called procedure declares at least one result field, YIELD may generally not be omitted. However YIELD may always be omitted in a standalone procedure call. In this case, all result fields are yielded as newly-bound variables from the procedure call to the user.