How to use variables in variable length MATCH

Although a newbie, I think I'm familiar enough to manage variable length MATCHES (such as:
MATCH lp = (begin:DBTable)-[:FKC*3..8]->(end:DBTable)
-- find any Foreign Key Constraint paths between two Tables of at least three and less than or equal to eight long)

My question relates to the syntax required to use variables instead of the "3" and "8". I can calculate the minimum and maximum path length to apply "further up the chain". However, I'm unsure how to get them into the MATCH statement.
In some of my attempts, Neo4j suggested using literal maps instead of parameter maps. But unfortunately, that was just more "gibberish" to me.

Can some kind soul enlighten me, please?
TIA,
Paolo

[Edit: If the variables were parameters, would that change the syntax?]

You can't provide the min and max path length values as parameters. You can use the apoc.run procedure to dynamically build the cypher statement using your parameters and then have the apoc procedure execute it.

Hi Gary, thanks for that! I suspected as much. I'll try the apoc.run procedure.

Paolo

1 Like