cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Apoc trigger parametrized query

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

@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

@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

All the sessions of the conference are now available online