2

I get error while passing parameter as property name. I did not get any error while passing parameter as property value by writing {param}. But this is not working in the case of passing parameter as property name.

Here is my code.

query = 'Merge(c1:Customer{user_id: {user_id1},{user_id2}:{cell}})'
g.run(query, user_id1=int(row['user_id']), user_id2=str(cidx),cell=cell) 

Here cidx, cell, row['user_id'] are parameters.

{user_id1} parameter is working.

But it does not take {user_id2} as parameter to add property name

PowerStat
  • 3,757
  • 8
  • 32
  • 57
  • 1
    What error do you get? And could you please provide some code? Which code you tried is not working and which does work? – John Archer Apr 11 '19 at 11:09
  • Hi John, Thanks for replying.Here is my code. query = 'Merge(c1:Customer{user_id: {user_id1},{user_id2}:{cell}})' g.run(query,user_id1=int(row['user_id']),user_id2=str(cidx),cell=cell) Here cidx, cell, row['user_id'] are parameters. {user_id1} parameter is working. But it does not take {user_id2} as parameter to add property name. – Avinash Shetty Apr 11 '19 at 11:20

1 Answers1

0

Cypher queries cannot be parametrized by Property names.

Parameters can be used for:

  • literals and expressions
  • node and relationship ids
  • for explicit indexes only: index values and queries

Parameters cannot be used for the following constructs, as these form part of the query structure that is compiled into a query plan:

  • property keys; so, MATCH (n) WHERE n.$param = 'something' is invalid

  • relationship types

  • labels

Refer Neo4j Documentation for more details.

EDIT:

You can format string to add property name as:

query = 'Merge(c1:Customer{user_id: {user_id1}, %s :{cell}})' % str(cidx)

Remove the parameter user_id2 from run method:

g.run(query, user_id1=int(row['user_id']), cell=cell) 
Rajendra Kadam
  • 4,004
  • 1
  • 10
  • 24
  • Any other alternatives? – Avinash Shetty Apr 11 '19 at 11:14
  • You can format the string in python, before running. Can you share your code snippet in the question? – Rajendra Kadam Apr 11 '19 at 11:16
  • You can refer this question for details: https://stackoverflow.com/questions/55006763/allow-parameters-for-depth-in-cypher-query/55007944#55007944 – Rajendra Kadam Apr 11 '19 at 11:17
  • Hi Raj,Thanks for the information. Here is my code. query = 'Merge(c1:Customer{user_id: {user_id1},{user_id2}:{cell}})' g.run(query,user_id1=int(row['user_id']),user_id2=str(cidx),cell=cell) Here cidx, cell, row['user_id'] are parameters. {user_id1} parameter is working. But it does not take {user_id2} as parameter to add property name – Avinash Shetty Apr 11 '19 at 11:24