1

According to the sample code at http://docs.neo4j.org/chunked/2.0.0-M03/rest-api-transactional.html I'm trying to use the MERGE statement.

But when I apply the following statement:

{
    "statements": [
        {
            "statement": "MERGE (p:PERSON { identification }) ON CREATE p SET { properties } ON MATCH p SET { properties } RETURN p",
            "parameters": {
                "identification": {
                    "guid": "abc123xyz"
                },
                "properties": {
                    "lastName": "Doe",
                    "firstName": "John"
                }
            }
        }
    ]
}

it gets back with the following 2 errors:

  • { identification }

code: 42000, status: STATEMENT_EXECUTION_ERROR, message: Tried to set a property to a collection of mixed types. List(Map(guid -> abc123xyz))

  • SET { properties }

code: 42001, status: STATEMENT_SYNTAX_ERROR", message: =' expected butO' found\n\nThink we should have …

Can this not be done this way (yet) or am I missing something?

Thanks for your help

Daniel

3 Answers 3

1

It seems you've discovered a bug. I've reported the issue here:

https://github.com/neo4j/neo4j/issues/975

Sign up to request clarification or add additional context in comments.

Comments

1

The issue is that MERGE needs to know the keys you will search on in advance. Passing a map of parameters hides this.

To achieve the same, list each key explicitly. If you still want to pass them all in a single map, you can probably do something like: MERGE (p:Person {name: {merge_map}.name, email: {merge_map}.email}).

Comments

0

Daniel,

I think you have to use SET differently, something like this:

MERGE (p:PERSON { identification }) 
ON CREATE p SET p={ properties } 
ON MATCH p SET p={ properties } 
RETURN p

But I'm not sure if that SET overrides all your properties. So it might be that you have to specify them one by one.

{
    "statements": [
        {
            "statement": "MERGE (p:PERSON { guid : {guid} }) 
             ON CREATE p SET p.lastName={lastName},p.firstName={ firstName } 
             ON MATCH  p SET p.lastName={lastName},p.firstName={ firstName }
             RETURN p",
            "parameters": {
               "guid": "abc123xyz",
               "lastName": "Doe",
               "firstName": "John"
            }
        }
    ]
}

2 Comments

Great, thanks, that solves the part of setting the properties. I guess that your second piece of code is not really handy. Is there any chance for a construct like ... ON MATCH p ADD|APPEND|OVERRIDE p={properties} ... ? And do you have a solution for the { identification } problem too?
Another question: wouldn't it make sense to be able to parameterize the labels part, i.e. "MERGE (p:{labels} ..."?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.