Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-12-2021 12:53 PM
I am trying to pass on the parameter to the cypher query in a function but it is not returning the results as expected. First error was ClientError: {code: Neo.ClientError.Statement.ParameterMissing} {message: Expected parameter(s): x}
I checked it on another forum where I also had to pass the parameter along with query run session I did so and error disappeared but still it didn't get the results as expected and returned the empty nodes.
In the graph db the nodes are connected with 4 types of relationships with an ids.
This is what I have tried so far:
def get_objects(x):
query = ''' MATCH (p)-[r]->(a) where r.id = $x RETURN p.id; '''
resultNodes = session.run(query, x = x)
df = DataFrame(resultNodes)
print(df)
return df
def find_max_1():
authors,terms,venues,papers=0,0,0,0
authors=get_objects(1).max()
terms=get_objects(2).max()
venues=get_objects(3).max()
papers=get_objects(4).max()
return authors,terms,venues,papers
def main():
m = m=find_max_1()
if __name__ == "__main__":
main()
and the output is:
Empty DataFrame
Columns: []
Index: []
Empty DataFrame
Columns: []
Index: []
Empty DataFrame
Columns: []
Index: []
Empty DataFrame
Columns: []
Index: []
I also checked giving the absolute value as ''' MATCH (p)-[r]->(a) where r.id = '1' RETURN p.id '''
into the function, it worked fine but there is a problem when i pass it through the function?
Any kind of help in right direction would be appreciated.
Thanks in advance.
Solved! Go to Solution.
04-12-2021 02:10 PM
Hello @mumarhafiz and welcome to the Neo4j community
In your example, you passed a String:
MATCH (p)-[r]->(a) where r.id = '1' RETURN p.id
So you should write:
query = "MATCH (p)-[r]->(a) where r.id = toString($x) RETURN p.id;"
or
query = "MATCH (p)-[r]->(a) where r.id = $x RETURN p.id;"
resultNodes = session.run(query, x=str(x))
Moreover, do you have an id
parameter on your nodes and relations or do you want to use the Neo4j internal ID? If it's the Neo4j internal ID, you should have a look at id().
Regards,
Cobra
04-12-2021 02:10 PM
Hello @mumarhafiz and welcome to the Neo4j community
In your example, you passed a String:
MATCH (p)-[r]->(a) where r.id = '1' RETURN p.id
So you should write:
query = "MATCH (p)-[r]->(a) where r.id = toString($x) RETURN p.id;"
or
query = "MATCH (p)-[r]->(a) where r.id = $x RETURN p.id;"
resultNodes = session.run(query, x=str(x))
Moreover, do you have an id
parameter on your nodes and relations or do you want to use the Neo4j internal ID? If it's the Neo4j internal ID, you should have a look at id().
Regards,
Cobra
04-12-2021 06:28 PM
Thanks for your response. Meanwhile I tried the other way and convert the parameter to string separately and then passed to cypher statement. It worked in my scenario, but this is clean and efficient.
And yes, I have the id
parameter on each of the nodes and also for the relations.
Thanks for your help.
All the sessions of the conference are now available online