cancel
Showing results for 
Search instead for 
Did you mean: 

Apoc trigger parametrized query

notdodo
Node

I've opened this issue because I think that the Run function does not perform the parameter substitution but I'm not sure if the code that I wrote is wrong or the problem is in the driver...

  • Go
1 ACCEPTED SOLUTION

giuseppe_villan
Graph Fellow

@notdodo

As Florent rightly said into the GitHub issue thread,
the $idP present in the second parameter of apoc.trigger.add is entirely managed by APOC.

Anyway, luckily is possible to pass a configuration to "transfer" your parameter from go-driver to apoc, see here in "optional params" section.
That is, you could change your query in this way, by adding {params: {idP: $idP}}:

CALL apoc.trigger.add("create-rel", 
			"UNWIND $createdNodes as node WITH node
			WHERE (node:A)
			MATCH (p:P) WHERE id(p) = toInteger($idP)
			MERGE (p)-[r:REL]->(node)",
       		{phase: 'before'}, {params: {idP: $idP}})

I haven't replicated the problem with Go because I don't know it, but via Neo4j Desktop,
however I believe it should work here too.

View solution in original post

2 REPLIES 2

giuseppe_villan
Graph Fellow

@notdodo

As Florent rightly said into the GitHub issue thread,
the $idP present in the second parameter of apoc.trigger.add is entirely managed by APOC.

Anyway, luckily is possible to pass a configuration to "transfer" your parameter from go-driver to apoc, see here in "optional params" section.
That is, you could change your query in this way, by adding {params: {idP: $idP}}:

CALL apoc.trigger.add("create-rel", 
			"UNWIND $createdNodes as node WITH node
			WHERE (node:A)
			MATCH (p:P) WHERE id(p) = toInteger($idP)
			MERGE (p)-[r:REL]->(node)",
       		{phase: 'before'}, {params: {idP: $idP}})

I haven't replicated the problem with Go because I don't know it, but via Neo4j Desktop,
however I believe it should work here too.

Hi @giuseppe.villani.

Thank you for your response and solution; it worked well.
Sorry I've missed the additional params parameter.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.