Call APOC procedure in a subquery

Viewed 13

I am trying to set labels dynamically with the apoc.create.setLabels function:

:auto MATCH (n:TempNode)
CALL {
    with n
    CALL apoc.create.setLabels( n, [ n.type ] ) YIELD node
} IN TRANSACTIONS;

I get a strange error that I never saw before:

Neo.ClientError.Statement.SyntaxError

Variable `n` not defined (line 3, column 10 (offset: 35))
"    with n"
          ^

Any ideas why this fairly simple query does not work?

1 Answers

The Cypher queries require that they should end either with RETURN or with some write operation, using MERGE, SET etc.

Both of your inner and outer queries return nothing, so try returning something like this:

:auto MATCH (n:TempNode)
CALL {
    with n
    CALL apoc.create.setLabels( n, [ n.type ] ) YIELD node
    RETURN node
} IN TRANSACTIONS
RETURN node;
Related