question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using matched node assignments in merge

See original GitHub issue

Hi,

I’m trying to create a MERGE for a relationship after a MATCH statement, as described in MERGE: neo4j documentation. However I’m having issues re-using the node-assignments.

The query I’m trying to produce is:

MATCH (a:`Article` {`article_id`: '123456'}),(p:`Product` {`product_id`: '1234567'})
MERGE a-[r:BELONGS_TO]->p

However I seem to run into two issues; the first is a multiple match, I tried defining it as: p.MATCH.node(...).node(...) this outputs a non comma separated MATCH sequence which turns unusable. How would I achieve a comma separated MATCH sequence (as shown in the referenced documentation)?

Secondly I can’t seem to re-use the assigned node MATCH, in the above case assigned “a”:

p.MERGE.a.rel_out(labels="BELONGS_TO").p

Update What I’m trying to achieve is something similar to this:

MATCH(a:Article{product_id: '1234567'}), (p:Product{product_id: '1234567'})
MERGE (a)-[r:PART_OF]->(p)
RETURN a, r, p

Any ideas on this?

Thank you in advance

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
emehrkaycommented, Nov 13, 2018

Edit: as you can see my return statement is wrong. You need to do it the way I described, with parens

p.RETURN(__.a, __.p, __.r)
1reaction
emehrkaycommented, Nov 13, 2018

The best way to handle this is to use the Anon class – __ and to execute MATCH with par’s

p.MATCH(__.node('a', 'Article', product_id='1234567'), __.node('p', 'Product', product_id='1234567'))

screen shot 2018-11-13 at 3 14 26 pm

You can add parens to all of the statements and it will generate a list of comma-separated items https://github.com/emehrkay/Pypher#statement

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypher: How to match node based on property and then set or ...
Whenever we execute a merge query, a node is either matched or created. Using on create and on the match, you can set...
Read more >
MERGE - Cypher Manual - Neo4j
Merge with ON MATCH​​ Merging nodes and setting properties on found nodes. The query finds all the Person nodes, sets a property on...
Read more >
Match and Merge Documentation - Task 3: Setting up matching
Task 3: Overview. A matching operation compares data from two or more records to find potential duplicates. You create a Matching policy to...
Read more >
Merge - execute insert or update when matched depdenidng ...
If you use the 100 4 TRUE row first, this will update the last row in the target table. It will change the...
Read more >
MERGE (preview) - Amazon Redshift
Next, merge the source table into the target table, updating the target table with matching rows and insert rows from the source table...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found